Codeforces Round #369 (Div. 2)

A.

6
OO|OX
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX


YES
++|OX
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX


4
XO|OX
XO|XX
OX|OX
XX|OX


NO


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#define LiangJiaJun main
#define LL long long
#define pa pair<int,int>
using namespace std;
char mp[1004][14];
int n;
void print(){
for(int i=1;i<=n;i++){
for(int j=1;j<=5;j++)printf("%c",mp[i][j]);
printf("\n");
}
}
int LiangJiaJun(){
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%s",mp[i]+1);
for(int i=1;i<=n;i++){
if(mp[i][1]=='O'&&mp[i][2]=='O'){
mp[i][1]=mp[i][2]='+';
printf("YES\n");print();return 0;
}
if(mp[i][4]=='O'&&mp[i][5]=='O'){
mp[i][4]=mp[i][5]='+';
printf("YES\n");print();return 0;
}
}
printf("NO\n");
return 0;
}


B.

PS：填的数字要大于0 。。。

3
4 0 2
3 5 7
8 1 6


9


4
1 1 1 1
1 1 0 1
1 1 2 1
1 1 1 1


-1


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#define LiangJiaJun main
#define LL long long
#define pa pair<int,int>
using namespace std;
int n;
long long a[504][504],x,y,s,t,q;
int check(){
if(a[x][y]<=0)return 0;

for(int i=1;i<=n;i++){
t=0;
for(int j=1;j<=n;j++)
t+=a[i][j];
if(t!=s){
return 0;
}
}
for(int j=1;j<=n;j++){
t=0;
for(int i=1;i<=n;i++)
t+=a[i][j];
if(t!=s){
return 0;
}
}
t=0;
for(int i=1;i<=n;i++)
t+=a[i][i];
if(t!=s) return 0;
t=0;
for(int i=1;i<=n;i++)
t+=a[i][n-i+1];
if(t!=s) return 0;
return 1;
}
int LiangJiaJun(){
scanf("%d",&n);
if(n==1){
cout<<"1";return 0;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)scanf("%d",&a[i][j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(a[i][j]==0){x=i;y=j;}
for(int i=1;i<=n;i++)
if(i!=x){
for(int j=1;j<=n;j++)
s+=a[i][j];
break;
}
for(int i=1;i<=n;i++)
q+=a[x][i];
a[x][y]=s-q;
if(!check())cout<<"-1"<<endl;
else cout<<a[x][y]<<endl;

return 0;
}



D.

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#define LiangJiaJun main
#define LL long long
#define pa pair<int,int>
#define MOD 1000000007LL
using namespace std;
struct edge{
int to,next;
}e[1000004];
int h[300004],ne=0,cnt=0;
int n,r,p,a[300004],belong[300004],low[300004],dfn[300004],SCC;
int val[300004];
bool inq[300004];
stack<int>ST;
LL temp=0;
LL ans=1;
void insert(int u,int v){
e[++ne].to = v;
e[ne].next = h[u];
h[u] = ne;
}
void tarjan(int x){
inq[x] = 1;
dfn[x] = low[x] = ++cnt;
ST.push(x);
for(int i=h[x];i;i=e[i].next){
if(!dfn[e[i].to]){
tarjan(e[i].to);
low[x] = min(low[x],low[e[i].to]);
}
else if(inq[e[i].to]) low[x] = min(low[x],dfn[e[i].to]);
}
if(low[x] == dfn[x]){
SCC++;int now = -1;
while(now != x){
now = ST.top();ST.pop();
belong[now] = SCC;
inq[now] = 0;
val[SCC]++;
}

}
}

int LiangJiaJun(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
insert(i,x);
}
for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);
int rest=n;//cout<<SCC<<endl;
for(int i=1;i<=SCC;i++){
if(val[i]==1)continue;
rest-=val[i];
temp=1;
for(int k=1;k<=val[i];k++)temp=(temp+temp)%MOD;
temp=(temp-2LL+MOD)%MOD;
ans=(ans*temp)%MOD;//cout<<ans<<endl;
}
temp=1;
for(int k=1;k<=rest;k++)temp=(temp+temp)%MOD;
ans=(ans*temp)%MOD;
printf("%I64d\n",ans);
return 0;
}

• 本文已收录于以下专栏：

[Codeforces Round #369 (Div. 2)D. Directed Roads]Tarjan强连通分量+组合计数

[Codeforces Round #369 (Div. 2)D. Directed Roads]Tarjan强连通分量题目链接：[Codeforces Round #369 (Div. 2)D. D...

[Codeforces Round #369 (Div. 2) C. Coloring Trees] DP

[Codeforces Round #369 (Div. 2) C. Coloring Trees] DP题目链接：[Codeforces Round #369 (Div. 2) C. Colorin...

codeforces Round #369 (Div. 2) C. Coloring Trees (三维DP)

﻿﻿ C. Coloring Trees time limit per test 2 seconds memory limit per test ...

Codeforces Round #369 (Div. 2) D. Directed Roads

• naipp
• 2016年08月30日 23:28
• 119

Codeforces Round #369 (Div. 2) B. Chris and Magic Square

B. Chris and Magic Square time limit per test 2 seconds memory limit per test 256 megaby...

Codeforces Round #369 (Div. 2) D. Directed Roads （dfs+组合数学 图论）

举报原因： 您举报文章：Codeforces Round #369 (Div. 2) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)