compatibility @ 2023-09-21 00:01:25
求助,VS上N=40也很快,结果洛谷全tle
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<math.h>
int main()
{
int arr[40005] = { 0 };
int count = 0;
char x = 0;
for (int i = 0; 1; i++)
{
x = getchar();
if (x != '\n')
{
count++;
arr[i] = x - '0';
}
else if (x == '\n')
break;
}
for (int i = count; i < count * count; i++)
{
x = getchar();
if (x != '\n')
arr[i] = x - '0';
else
arr[i] = getchar() - '0';
}
printf("%d ", count);
int b = 0;
for (int a = 0; b < count * count;a++ )
{
int k = 0;
if (a % 2 == 0)
{
while (arr[b] == 0)
{
if (b == count*count)
break;
k++;
b++;
}
printf("%d ", k);
}
else
{
while (arr[b] == 1)
{
if (b == count*count)
break;
k++;
b++;
}
printf("%d ", k);
}
}
return 0;
}
by DiThgtrE_lsy @ 2023-09-21 00:11:01
建议快读把break放到for的小括号里写,不然可能会炸
附上我的
#include<iostream>
#include<cstring>
using namespace std;
string a[205];
int x,y;
char c;
int main(){
cin>>a[0];
y=a[0].size();
for(int i=1;i<y;i++)
cin>>a[i];
c=48;
cout<<y<<" ";
for(int i=0;i<y;i++)
for(int j=0;j<y;j++)
{
if(a[i][j]==c)
x++;
else
{
cout<<x<<' ';
x=1;
if(c=='0')
c='1';
else c='0';
}
}
cout<<x<<endl;
return 0;
}
by wrkwrkwrk @ 2023-09-21 06:46:16
@compatibility 可能这个数据行尾不是换行符
by compatibility @ 2023-09-22 23:33:27
@wrkwrkwrk 那是什么?
by compatibility @ 2023-09-22 23:33:47
@DiThgtrE_lsy 哪里的break?
by wrkwrkwrk @ 2023-09-23 10:20:08
@compatibility 你可以试一下freopen读入数据@compatibility,最后不打换行符
by compatibility @ 2023-09-23 16:55:46
@wrkwrkwrk 什么是freopen?抱歉,我只学了c..
by wrkwrkwrk @ 2023-09-23 17:03:24
@compatibility 或者你可以在你的输入最后按下ctrl+z
by compatibility @ 2023-09-23 23:30:01
@wrkwrkwrk 不用啊,我在VS上照示例输入结果是对的,但洛谷就不行了,不知道为什么
by wrkwrkwrk @ 2023-09-24 08:09:27
@compatibility 就是要ctrl+z才能出发(或者试试在终端运行?)