竞赛讨论区 > 求大佬改进:H题——本题主要考察了DFS
头像
不勇敢的牛牛君258
发布于 2023-01-18 18:31 上海
+ 关注

求大佬改进:H题——本题主要考察了DFS

我思路是对的,但一直超时。想来想去也不知道怎么减少时间复杂度。。。

#include <iostream>

#include <math.h>

#include <iomanip>

using namespace std;

int main()

{

int t,n, x,y;

int b[20];

char a[400][4];

cin >> t;

int t1 = t;

while (t)

{

cin >> n;

x = 0;

y = 0;

b[t1 - t] = 0;

for (int i = 1; i < n * n; i++)

for (int j = 1; j <= 4; j++)

{

cin >> a[i][j];

if (a[i][j] == '1')

x++;

if (a[i][j] == '2')

x--;

}

b[t1-t]= 10 + x;

t--;

}

for (int i=0;i<t1;i++)

{

cout << b[i];

}

return 0;

}

全部评论

(1) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐