Codeforces Round #369 (Div. 2) A B 两水题 编码能力

202人阅读 评论(0)

A题：

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
string save[1010];
int main(){
int n,i,j;
scanf("%d",&n);
string t;
int flag = false;
for(i=1;i<=n;i++){
cin>>save[i];
if((save[i][0]=='O'&&save[i][1]=='O')||(save[i][3]=='O'&&save[i][4]=='O')){
if(!flag){
if(save[i][0]=='O'&&save[i][1]=='O'){
save[i][0]='+';
save[i][1]='+';
}else{
save[i][3]='+';
save[i][4]='+';
}
}
flag = true;
}
}
if(flag){
printf("YES\n");
for(i=1;i<=n;i++){
cout<<save[i]<<endl;
}
}else{
printf("NO\n");
}
return 0;
}
B题：

。。。。感觉自己好腊鸡啊。。什么时候div能稳做三题呢。。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=510;
const long long prime = 10000019;
int n,i,j;
long long save[maxn][maxn];
bool judge(){
long long now=0,sum=0;
bool flag = true;
bool can=true;
for(i=1;i<=n;i++){
if(can){
now = sum;
}
sum = 0;
can = true;
for(j=1;j<=n;j++){
if(save[j][i]==0){
can = false;
}
sum = (sum+save[j][i])%prime;
}
if(can){
if(now!=sum&&now!=0){
flag =false;
return false;
}
}
}
return  true;
}
long long result(int i0){
int it;
if(i0>1){
it=1;
}else if(i0==n){
it = 1;
}else{
it = n;
}
for(i=1;i<=n;i++){
}
}
int main(){
scanf("%d",&n);
int i0,j0;
if(n==1){
printf("1\n");
return 0;
}
long long now=0,sum=0;
bool flag = true;
bool can=true;
for(i=1;i<=n;i++){
if(can){
now = sum;
}
sum = 0;
can = true;
for(j=1;j<=n;j++){
scanf("%I64d",&save[i][j]);
if(save[i][j]==0){
i0=i,j0=j;
can = false;
}
sum = (sum+save[i][j])%prime;
}
if(can){
if(now!=sum&&now!=0){
flag =false;
}
}
}
if(flag){
long long sum1 = 0;
long long sum2 = 0;
bool can=true;
for(i=1;i<=n;i++){
if(save[i][i]==0){
can =false;
break;
}
sum1 = (sum1+save[i][i])%prime;
}
for(i=1;i<=n;i++){
if(save[i][n-i+1]==0){
can =false;
break;
}
sum2 = (sum2+save[i][n-i+1])%prime;
}
if(sum1!=sum2&&can){
printf("-1\n");
}else if(sum1!=now&&can){
printf("-1\n");
}else{
if(judge()){
if(result(i0)>0){
save[i0][j0]=result(i0);
sum1=0,sum2=0;
for(i=1;i<=n;i++){
sum1 = (sum1+save[i][i])%prime;
sum2 = (sum2+save[i][n-i+1])%prime;
}
if(n==2){
if(sum1==sum2&&judge()){
return 0;
}else{
printf("-1\n");
}
}
}
if(sum1==sum2&&sum1==now&&judge()){
}else{
printf("-1\n");
}
}else{
printf("-1\n");
}
}else{
printf("-1\n");
}
}else{
printf("-1\n");
}
}
}else{
printf("-1\n");
}
return 0;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：42845次
• 积分：2468
• 等级：
• 排名：第14980名
• 原创：210篇
• 转载：1篇
• 译文：0篇
• 评论：22条
最新评论