# Codeforces Round #369 (Div. 2)

127人阅读 评论(0)

Codeforces Round #369 (Div. 2)
qer 弱的可啪……

A
—————————————————————————————

（为什么这次码风这么奇怪啊 QAQQQQQQQQQQQQQQQQQQQQQ）

#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;

const int MAXN = 1000 + 10;
int n;
char z[MAXN][10];

inline void print()
{
puts("YES");
for(int i = 1; i <= n; i ++)
printf("%s\n",z[i]);
return;
}

inline bool Judge(int i, int j)
{
if(z[i][j] == z[i][j+1] && z[i][j] == 'O')
{
z[i][j] = z[i][j+1] = '+';
print();
return 1;
}
return 0;
}

int main()
{
char c;
cin >> n;
for(int i = 1; i <= n; i ++)
scanf("%s",z[i]);
for(int i = 1; i <= n; i ++)
{
if(Judge(i,0))
return 0;
if(Judge(i,3))
return 0;
}
puts("NO");
return 0;
}

B
—————————————————————————————

（我不会告诉你们我蒟蒻全犯了）

#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

const int MAXN = 500 + 5;
int n;
LL maps[MAXN][MAXN];
LL R[MAXN], C[MAXN], Dia[2];

void J_R()
{
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
R[i] += maps[i][j];
}

void J_C()
{
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; j ++)
C[i] += maps[j][i];
}

void J_Z()
{
for(int i = 1; i <= n; i ++)
Dia[0] += maps[i][i];
}

void J_F()
{
for(int i = n, j = 1; i >= 1, j <= n; i --, j ++)
Dia[1] += maps[i][j];
}

int main()
{
int x = 0, y = 0;
scanf("%d",&n);
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= n; j ++){
scanf("%d",&maps[i][j]);
if(!maps[i][j] && !x && !y){
x = i; y = j;
}
}
}
if(n == 1 && !maps[n][n])
{
puts("1");
return 0;
}
J_R();J_C();
LL RC = 0, CC = 0;
sort(R+1,R+n+1);
sort(C+1,C+n+1);
RC = abs(R[2] - R[1]);
CC = abs(C[2] - C[1]);
bool weiyi = true;
if(R[3] && R[3] != R[2])
weiyi = false;
if(C[3] && C[3] != C[2])
weiyi = false;
if(RC == CC && RC && weiyi)
{
maps[x][y] = RC;
J_Z();J_F();
if(Dia[0] == Dia[1] && Dia[0] == R[n] && R[n] == C[n])
{
printf("%I64d\n",RC);
return 0;
}
else puts("-1");
}
else puts("-1");
return 0;
}


/*
Input
7
250000000 1000000000 1000000000 250000000 1000000000 1000000000 250000000
1000000000 250000000 1000000000 250000000 1000000000 250000000 1000000000
1000000000 1000000000 250000000 250000000 250000000 1000000000 1000000000
250000000 250000000 250000000 0 250000000 250000000 250000000
1000000000 1000000000 250000000 250000000 250000000 1000000000 1000000000
1000000000 250000000 1000000000 250000000 1000000000 250000000 1000000000
250000000 1000000000 1000000000 250000000 1000000000 1000000000 250000000
3250000000
*/

/*
Input
10
92 67 99 74 1 51 8 58 15 40
17 42 24 49 0 26 83 33 90 65
98 73 80 55 7 57 14 64 16 41
23 48 5 30 82 32 89 39 91 66
4 54 81 56 88 63 20 70 22 47
79 29 6 31 13 38 95 45 97 72
85 60 87 62 19 69 21 71 3 28
10 35 12 37 94 44 96 46 78 53
86 61 93 68 25 75 2 52 9 34
11 36 18 43 100 50 77 27 84 59
76
*/

以上是 2016-08-30 14:04


2016-10-19 考试考到了这个题，然而只拿了90没判n==1 的情况， 但是感觉思路比上面清晰了许多。


#include <iostream>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;

const LL MAXN = 500 + 5;
LL n, zx = 0, cx = 0;
LL maps[MAXN][MAXN];
LL r[MAXN], c[MAXN];

void Get_r()
{
for(LL i = 1; i <= n; i ++)
for(LL j = 1; j <= n; j ++)
r[i] += maps[i][j];
}

void Get_c()
{
for(LL i = 1; i <= n; i ++)
for(LL j = 1; j <= n; j ++)
c[j] += maps[i][j];
}

void Get_zx()
{
for(LL i = 1; i <= n; i ++)
zx += maps[i][i];
}

void Get_cx()
{
for(LL i = 1, j = n; i <= n, j >= 1; i ++, j --)
cx += maps[i][j];
}

int main()
{
cin >> n;
memset(r,0,sizeof(r)); memset(c,0,sizeof(c));
for(LL i = 1; i <= n; i ++)
for(LL j = 1; j <= n; j ++)
scanf("%lld", &maps[i][j]);

Get_r(); Get_c(); Get_zx(); Get_cx();

bool Bigflag = 0;
LL h = 0;
LL ans = 0, ans1 = 0, ans2 = 0, ans3 = 0;

// 行
LL i = 1;
while(i < n)
{
if(r[i] != r[i+1])
{
if(h < 2)
{
ans1 = abs(r[i+1]-r[i]);
h ++;
}
else Bigflag = 1;
}
i ++;
}
if(Bigflag)
{
puts("-1");
return 0;
}
// 列
i = 1;
h = 0;
while(i < n)
{
if(c[i] != c[i+1])
{
if(h < 2)
{
ans2 = abs(c[i+1]-c[i]);
h ++;
}
else Bigflag = 1;
}
i ++;
}
if(Bigflag)
{
puts("-1");
return 0;
}

ans3 = abs(zx-cx);

//  cout << ans1 << " " << ans2 << " " << ans3 << endl;
if(ans3)
{
if(ans1 == ans2 && ans2 == ans3)
{
if(!ans1)
puts("1");
else cout << ans1 << endl;
}
else puts("-1");
}
else
{
if(ans1 == ans2)
{
if(!ans1)
puts("1");
else cout << ans1 << endl;
}
else puts("-1");
}
return 0;
}

/*
5
1067 1066 1066 1066 1067
1066 1067 1066 1067 1066
1066 1066 1067 1066 1066
1066 1067 1066 1067 1066
1067 1066 1066 1066 0

*/
0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：30522次
• 积分：1616
• 等级：
• 排名：千里之外
• 原创：121篇
• 转载：6篇
• 译文：0篇
• 评论：49条
文章分类
LOI-55
LOI-56
QQ邮箱->>