はい。
Codeforces Round #405 (Div.2)
#include<bits/stdc++.h>
using namespace std;
#define sc2(a,b) scanf("%d %d",&a,&b)
int main(){
int a,b,ans=0;
sc2(a,b);
for(;;){
a*=3;
b*=2;
ans++;
if (a>b) break;
}
printf("%d\n",ans);
return 0;
}
Aを3倍とBを2倍し続けてAがBより大きくなるのはいつか。
B. Bear and Friendship Condition
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define per(i,n) for(int i=n-1;i>=0;--i)
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define sc3(a,b,c) scanf("%d %d %d",&a,&b,&c)
struct UnionFind {
vector<int> data;
UnionFind(int size) : data(size, -1) {}
bool unite(int x, int y) {
x=root(x), y=root(y);
if (x!=y) {
if (data[y]<data[x]) {
swap(x, y);
}
data[x]+=data[y], data[y]=x;
}
return x!=y;
}
bool find(int x, int y) {
return root(x)==root(y);
}
int root(int x) {
return data[x]<0 ? x : data[x]=root(data[x]);
}
int size(int x) {
return -data[root(x)];
}
};
int chk[150005];
int main(){
bool f=1;
int n,m,a,b,ans;
sc2(n,m);
UnionFind uf(n+1);
rep(i,m) {
sc2(a,b);
uf.unite(a,b);
chk[a]++;
chk[b]++;
}
rep(i,n+1){
if (uf.size(i)!=chk[i]+1) f=0;
}
printf("%s\n",f?"YES":"NO");
return 0;
}
Noteをよく見る。同じグループ内の頂点同士で直接接続する辺がないとだめらしい。各頂点の出現回数、辺の本数を数えました。UnionFindで自グループ内の頂点数と入力受け取りで数えておいた辺の本数を照らし合わせればYESとNOが決められるはずです。
C. Bear and Different Names
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define sc2(a,b) scanf("%d %d",&a,&b)
int main(){
int n,k,x[100];
char s[10];
sc2(n,k);
rep(i,100) x[i]=i;
rep(i,n){
scanf("%s",s);
if (s[0]=='N') x[i+k-1]=x[i];
}
rep(i,n) printf("%c%c%c",x[i]/25+'A',x[i]%25+'a',i==n-1?'\n':' ');
return 0;
}
先頭から数え始めを1人ずらしつつk人のグループ内に同じ名前がいるかどうか。
問題の解法とは別件ですが空白区切りのYES NOを受け取るのに char s[3];
はサイズが足りないです。
参加者最大50人で名前文字列が最長10なので雑に命名しても全員違う名前が可能です。
全員違う名前を用意しておきます。NOのときだけ終わり右端の人を先頭左端の人と同じ名前にします。