Warning: mysqli_query(): (HY000/1021): Disk full (/tmp/#sql_51b_2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device") in /opt/lampp/htdocs/wordpress/wp-includes/wp-db.php on line 2033
AtCoder Beginner Contest 296 A-E()-其他 – 知识波

# AtCoder Beginner Contest 296 A-E()-其他

## AtCoder Beginner Contest 296 A-E()

### A – Alternately

`````` 1 void solve(){
3     string s;
4     cin>>s;
5     int ans=1;
6     for(int i=0;i<s.size()-1;i++){
7         if(s[i]==s[i+1])ans=0;
8     }
9     puts(ans>0?"Yes":"No");
10 }``````

### B – Chessboard

``````void solve(){
int n=8,ansx,ansy;
for(int i=1;i<=8;i++){
for(int j=1;j<=8;j++){
char a;
cin>>a;
if(a=='*'){
ansx=i;
ansy=j;
}
}
}
char ans;
ans=ansy-1+'a';
cout<<ans<<9-ansx<<endl;
}``````

### C – Gap Existence

``````#define int long long
map<int,int>mp;
void solve(){
for(int i=1;i<=n;i++){
if(mp[x+k]||mp[x-k]){
ans=1;
}

}
puts(ans>0?"Yes":"No");
}``````

### D – M<=ab

`````` 1 void solve(){
3     int ans=INF;
4     for(int i=1;i<=min(n,1000000ll);i++){
5         int j=m/i;
6         if(i*j<m){
7             j++;
8         }
9         if(j<=n){
10             ans=min(ans,i*j);
11         }
12     }
13     if(ans==INF){
14         cout<<-1<<"\n";
15     }else cout<<ans<<"\n";
16 }``````

### E – Transition Game

``````int h[N], e[N], ne[N], idx, a[N];
int dfn[N], low[N], timestamp;
int stk[N], top;
bool in_stk[N];
int id[N], scc_cnt, siz[N];
e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}
void tarjan(int u){
dfn[u] = low[u] = ++ timestamp;
stk[ ++ top] = u, in_stk[u] = true;
for (int i = h[u]; ~i; i = ne[i]){
int j = e[i];
if (!dfn[j]){
tarjan(j);
low[u] = min(low[u], low[j]);
}
else if (in_stk[j])
low[u] = min(low[u], dfn[j]);
}
if (dfn[u] == low[u]){
++ scc_cnt;
int y;
do {
y = stk[top -- ];
in_stk[y] = false;
id[y] = scc_cnt;
siz[scc_cnt]++;
} while (y != u);
}
}
void solve(){
idx = 0;
memset(h, -1, sizeof h);
for(int i=1;i<=n;i++){
if(i!=a[i]){
}
}
for(int i=1;i<=n;i++){
if(a[i]!=i&&!dfn[i]){
tarjan(i);
}
}
for(int i=1;i<=n;i++){
if(a[i]==i||siz[id[i]]>1){
ans++;
}
}
cout<<ans<<endl;
}``````
————————

### A – Alternately

`````` 1 void solve(){
3     string s;
4     cin>>s;
5     int ans=1;
6     for(int i=0;i<s.size()-1;i++){
7         if(s[i]==s[i+1])ans=0;
8     }
9     puts(ans>0?"Yes":"No");
10 }``````

### B – Chessboard

``````void solve(){
int n=8,ansx,ansy;
for(int i=1;i<=8;i++){
for(int j=1;j<=8;j++){
char a;
cin>>a;
if(a=='*'){
ansx=i;
ansy=j;
}
}
}
char ans;
ans=ansy-1+'a';
cout<<ans<<9-ansx<<endl;
}``````

### C – Gap Existence

``````#define int long long
map<int,int>mp;
void solve(){
for(int i=1;i<=n;i++){
if(mp[x+k]||mp[x-k]){
ans=1;
}

}
puts(ans>0?"Yes":"No");
}``````

### D – M<=ab

`````` 1 void solve(){
3     int ans=INF;
4     for(int i=1;i<=min(n,1000000ll);i++){
5         int j=m/i;
6         if(i*j<m){
7             j++;
8         }
9         if(j<=n){
10             ans=min(ans,i*j);
11         }
12     }
13     if(ans==INF){
14         cout<<-1<<"\n";
15     }else cout<<ans<<"\n";
16 }``````

### E – Transition Game

``````int h[N], e[N], ne[N], idx, a[N];
int dfn[N], low[N], timestamp;
int stk[N], top;
bool in_stk[N];
int id[N], scc_cnt, siz[N];
e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}
void tarjan(int u){
dfn[u] = low[u] = ++ timestamp;
stk[ ++ top] = u, in_stk[u] = true;
for (int i = h[u]; ~i; i = ne[i]){
int j = e[i];
if (!dfn[j]){
tarjan(j);
low[u] = min(low[u], low[j]);
}
else if (in_stk[j])
low[u] = min(low[u], dfn[j]);
}
if (dfn[u] == low[u]){
++ scc_cnt;
int y;
do {
y = stk[top -- ];
in_stk[y] = false;
id[y] = scc_cnt;
siz[scc_cnt]++;
} while (y != u);
}
}
void solve(){
idx = 0;
memset(h, -1, sizeof h);
for(int i=1;i<=n;i++){
if(i!=a[i]){
}
}
for(int i=1;i<=n;i++){
if(a[i]!=i&&!dfn[i]){
tarjan(i);
}
}
for(int i=1;i<=n;i++){
if(a[i]==i||siz[id[i]]>1){
ans++;
}
}
cout<<ans<<endl;
}``````