谜一般的getchar/scanf

P1736 创意吃鱼法

Ηydra @ 2018-07-05 15:45:39

本地用getchar()/scanf读入结果正确,提交到洛谷上10分……改成cin竟然AC了?!所以getchar()/scanf在Windows下和Linux下的用法不一样吗?

#include <cstdio>
#include <iostream>

using namespace std;

bool a[2505][2505];
bool vis1[2505][2505], vis2[2505][2505];
int cnt[2505][2505], s;

inline int count(int x1, int y1, int x2, int y2)
{
    return cnt[x2][y2] - cnt[x1-1][y2] - cnt[x2][y1-1] + cnt[x1-1][y1-1];
}

int main()
{
    int total, x, y;
    int n, m;
    char c;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
    {
        getchar();
        c = getchar();
        if (c == '1') a[i][j] = 1;
        cnt[i][j] = cnt[i-1][j] + cnt[i][j-1] - cnt[i-1][j-1] + a[i][j];
    }
    for (int i = 1; i <= n - s; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            if (!a[i][j] || a[i+1][j]) continue;
            total = 1;
            x = i + 1;
            y = j + 1;
            if (!vis1[i][j] && j + s <= m)
            while (a[x][y] && count(i, j, x, y) == total+1)
            {
                ++total;
                vis1[x][y] = 1;
                ++x;
                ++y;    
            }
            s = max(s, total);
            x = i + 1;
            y = j - 1;
            if (!vis2[i][j] && j >= s)
            while (a[x][y] && count(i, y, x, j) == total+1)
            {
                ++total;
                vis2[x][y] = 1;
                ++x;
                --y;    
            }
            s = max(s, total);
        }
    }
    printf("%d\n", s);
    return 0;
}

by SeKong @ 2018-07-05 15:57:08

Why use 'getchar' like this?Without 'while'?

Who told you that there're exactly two spaces between the lines?

How about three spaces?I can type one more space by myself.It's legal.

And also, in Linux '\n' ends a line while '\r\n' ends a lind in Windows.


by Captain_Paul @ 2018-07-05 16:18:06

@Skqliao %全篇英语dalao


by Ηydra @ 2018-07-05 16:27:59

@Skqliao 哦,谢谢大佬%


by SeKong @ 2018-07-05 18:00:05

@Captain_Paul I just can't type Chinese in luogu using this device,it's strange.


by Owen_codeisking @ 2018-07-09 11:04:51

@Skqliao I can't understand what you mean due to my poor Chinglish/Engnese


by EMT__Mashiro @ 2018-08-07 10:24:44

翻译:
为什么要这样使用getchar?在没有while的情况下?
谁告诉你两行之间一定只有两个空格?
三个空格如何?我可以自己多打一个空格,这是合法的
并且,Windows的换行符是'\r\n'而Linux是'\n'


by EMT__Mashiro @ 2018-08-07 10:25:03

渣翻勿喷


|