首页 > 其他 > 详细

codeforces gym101243 A C D E F G H J

时间:2017-07-05 23:31:31      阅读:388      评论:0      收藏:0      [点我收藏+]

gym101243

A

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<map>
 7 #include<queue>
 8 #include<stack>
 9 #include<vector>
10 #include<bitset>
11 #include<set>
12 #define ll __int64
13 #define mod 100000000
14 #define N 5e6+10
15 #define M 1e
16 using namespace std;
17 int n,k;
18 int main()
19 {
20     freopen("input.txt","r",stdin);
21     freopen("output.txt","w",stdout);
22     scanf("%d %d",&n,&k);
23     printf("%d\n",max((n*2+k-1)/k,2));
24    
25  return 0;
26 }

 

C

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<map>
 7 #include<queue>
 8 #include<stack>
 9 #include<vector>
10 #include<bitset>
11 #include<set>
12 #define ll __int64
13 #define mod 100000000
14 #define N 5e6+10
15 #define M 1e
16 using namespace std;
17 int h,w;
18 int x[250005],y[250005];
19 int main()
20 {
21     freopen("input.txt","r",stdin);
22     freopen("output.txt","w",stdout);
23     int exm=0;
24     scanf("%d %d",&h,&w);
25     if(h<=1||w<=1)
26     {
27         printf("0\n");
28         return 0;
29     }
30     if(h%2==0){
31         for(int i=h-1;i>=1;i-=2){
32             for(int j=1;j<w;j++){
33                 x[exm]=i;
34                 y[exm]=j;
35                 exm++;
36             }
37             if(i!=1){
38                 x[exm]=i-1;
39                 y[exm]=w-1;
40                 exm++;
41             }
42         }
43     }
44     else{
45           for(int i=h-1;i>=4;i-=2){
46             for(int j=1;j<w;j++){
47                 x[exm]=i;
48                 y[exm]=j;
49                 exm++;
50             }
51                 x[exm]=i-1;
52                 y[exm]=w-1;
53                 exm++;
54         }
55         for(int j=1;j<w;j+=2){
56             if(j!=w-1){
57                 x[exm]=2;
58                 y[exm]=j;
59                 exm++;
60                 x[exm]=1;
61                 y[exm]=j;
62                 exm++;
63                 x[exm]=1;
64                 y[exm]=j+1;
65                 exm++;
66             }
67             else{
68                 x[exm]=2;
69                 y[exm]=j;
70                 exm++;
71                 x[exm]=1;
72                 y[exm]=j;
73                 exm++;
74             }
75         }
76     }
77     printf("%d\n",exm);
78     for(int i=0;i<exm;i++)
79         printf("%d %d\n",x[i],y[i]);
80     return 0;
81 }

 

D

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<map>
 7 #include<queue>
 8 #include<stack>
 9 #include<vector>
10 #include<set>
11 using namespace std;
12 #define PI acos(-1.0)
13 typedef long long ll;
14 typedef pair<int,int> P;
15 const int maxn=1e4+100,maxm=1e5+100,inf=0x3f3f3f3f,mod=1e9+7;
16 const ll INF=1e13+7;
17 struct edge
18 {
19     int from,to;
20     int cost;
21 };
22 edge es[maxm];
23 priority_queue<P,vector<P>,greater<P> >que;
24 char s[200000];
25 int main()
26 {
27     freopen("input.txt","r",stdin);
28     freopen("output.txt","w",stdout);
29     cin>>s;
30     int n=strlen(s);
31     int ans=1;
32     for(int i=1;i<n;i++)
33     {
34         if(s[i]==E&&(s[i-1]==N||s[i-1]==S)) ans=(ans*2)%mod;
35         else if(s[i]==W&&(s[i-1]==N||s[i-1]==S)) ans=(ans*2)%mod;
36     }
37     cout<<ans<<endl;
38     return 0;
39 }

 

E

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<map>
 7 #include<queue>
 8 #include<stack>
 9 #include<vector>
10 #include<bitset>
11 #include<set>
12 #define ll __int64
13 #define mod 100000000
14 #define N 5e6+10
15 #define M 1e
16 using namespace std;
17 ll n,k,a[100005];
18 ll sum[100005];
19 int main()
20 {
21     freopen("input.txt","r",stdin);
22     freopen("output.txt","w",stdout);
23     scanf("%I64d %I64d",&n,&k);
24     sum[0]=0;
25     ll maxn=0;
26     int pos;
27     for(ll i=1; i<=n; i++)
28     {
29         scanf("%I64d",&a[i]);
30         sum[i]=sum[i-1]+a[i];
31         if(maxn<a[i])
32         {
33             pos=i;
34             maxn=a[i];
35         }
36     }
37     ll l,r;
38     ll ans1,ans2;
39     l=n-1+maxn;
40     r=sum[n];
41     ans1=max(0ll,k-pos+1)/l;
42     ans2=max(0ll,k-sum[pos-1])/r;
43     for(ll i=0; i<=ans1; i++)
44         if(k>=(pos-1+l*i)&&k<=(sum[pos-1]+r*i))
45         {
46             printf("YES\n");
47             return 0;
48         }
49     printf("KEK\n");
50     return 0;
51 }

 

 

F

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<map>
 7 #include<queue>
 8 #include<stack>
 9 #include<vector>
10 using namespace std;
11 typedef pair<int,int> P;
12 typedef long long ll;
13 const int maxn=1e3+100,maxm=1e6+100,inf=0x3f3f3f3f,mod=1e9+7;
14 const ll INF=1e13+7;
15 struct edge
16 {
17     int from,to;
18     char ch;
19 };
20 edge es[maxm];
21 int pa[maxn];
22 int findset(int x)
23 {
24     return pa[x]==x?x:pa[x]=findset(pa[x]);
25 }
26 void unit(int x,int y)
27 {
28     int fx=findset(x),fy=findset(y);
29     if(fx<=fy) pa[fx]=fy;
30     else pa[fy]=fx;
31 }
32 int in[maxn],out[maxn];
33 int ans[maxn];
34 int main()
35 {
36     freopen("input.txt","r",stdin);
37     freopen("output.txt","w",stdout);
38     int n,k;
39     scanf("%d%d",&n,&k);
40     for(int i=1; i<=n; i++) pa[i]=i;
41     memset(out,0,sizeof(out));
42     memset(in,0,sizeof(in));
43     for(int i=1; i<=k; i++)
44     {
45         scanf("%d%c%d",&es[i].from,&es[i].ch,&es[i].to);
46         if(es[i].ch===) unit(es[i].from,es[i].to);
47         else
48         {
49             if(es[i].ch==>) swap(es[i].from,es[i].to);
50             es[i].ch=<;
51         }
52     }
53     for(int i=1; i<=k; i++)
54     {
55         if(es[i].ch===) continue;
56         out[findset(es[i].from)]++,in[findset(es[i].to)]++;
57     }
58     for(int i=1; i<=n; i++)
59         if(in[i]&&out[i]) ans[i]=2;
60     for(int i=1; i<=k; i++)
61     {
62         if(es[i].ch===) continue;
63         if(ans[findset(es[i].from)]==2) ans[findset(es[i].to)]=3;
64         else if(ans[findset(es[i].to)]==2) ans[findset(es[i].from)]=1;
65     }
66     for(int i=1; i<=n; i++)
67     {
68         if(ans[findset(i)]==1) cout<<"B";
69         else if(ans[findset(i)]==2) cout<<"R";
70         else if(ans[findset(i)]==3) cout<<"W";
71         else cout<<"?";
72     }
73     cout<<endl;
74     return 0;
75 }

 

G

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<map>
 7 #include<queue>
 8 #include<stack>
 9 #include<vector>
10 #include<bitset>
11 #include<set>
12 #define ll __int64
13 #define mod 100000000
14 #define N 5e6+10
15 #define M 1e
16 using namespace std;
17 int n;
18 int main()
19 {
20     freopen("input.txt","r",stdin);
21     freopen("output.txt","w",stdout);
22     scanf("%d",&n);
23     int que[1005];
24     int jishu=0;
25     for(int i=2;i*i<=n;i++)
26     {
27         if(n%i==0)
28         {
29             int flag=0;
30             que[jishu++]=i;
31             while(n%i==0)
32             {
33                 flag++;
34                 n/=i;
35                 if(flag>2)
36                 {
37                     printf("NO\n");
38                     return 0;
39                 }
40             }
41         }
42     }
43     if(n>1)
44         que[jishu++]=n;
45     if(jishu==3)
46         printf("YES\n");
47     else
48         printf("NO\n");
49      return 0;
50 }

 

H

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<map>
 7 #include<queue>
 8 #include<stack>
 9 #include<vector>
10 #include<bitset>
11 #include<set>
12 #define ll __int64
13 #define mod 100000000
14 #define N 5e6+10
15 #define M 1e
16 using namespace std;
17 int n;
18 int main()
19 {
20     freopen("input.txt","r",stdin);
21     freopen("output.txt","w",stdout);
22     scanf("%d",&n);
23     if(n<10)
24     {
25         ll ans=8;
26         for(int i=2;i<=n;i++)
27             ans*=9;
28         printf("%I64d\n",ans);
29     }
30     else
31     {
32         ll ans=8;
33         for(int i=2;i<=9;i++)
34             ans*=9;
35         printf("%I64d",ans);
36         for(int i=10;i<=n;i++)
37             printf("0");
38         printf("\n");
39     }
40     return 0;
41 }

 

J

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<map>
 7 #include<queue>
 8 #include<stack>
 9 #include<vector>
10 using namespace std;
11 typedef pair<int,int> P;
12 typedef long long ll;
13 const int maxn=1e3+100,maxm=1e6+100,inf=0x3f3f3f3f,mod=1e9+7;
14 const ll INF=1e13+7;
15 struct edge
16 {
17     int from,to;
18     char ch;
19 };
20 edge es[maxm];
21 char num[maxn][10];
22 vector<int>G[maxn];
23 int cy[maxn],vis[maxn];
24 bool dfs(int u)
25 {
26     for(int i=0; i<G[u].size(); i++)
27     {
28         int v=G[u][i];
29         if(vis[v]) continue;
30         vis[v]=true;
31         if(cy[v]==-1||dfs(cy[v]))
32         {
33             cy[v]=u;
34             return true;
35         }
36     }
37     return false;
38 }
39 int solve(int n)
40 {
41     int ret=0;
42     memset(cy,-1,sizeof(cy));
43     for(int i=1; i<=n; i++)
44     {
45         memset(vis,0,sizeof(vis));
46         if(dfs(i)) ret++;
47     }
48     return ret;
49 }
50 int main()
51 {
52     freopen("input.txt","r",stdin);
53     freopen("output.txt","w",stdout);
54     int n,m;
55     scanf("%d%d",&n,&m);
56     for(int i=1; i<=n; i++) scanf("%s",num[i]);
57     for(int i=1; i<=m; i++) scanf("%s",num[i+n]);
58     for(int i=1; i<=n; i++)
59     {
60         for(int j=1; j<=m; j++)
61         {
62             if(num[i][0]+num[i][1]+num[i][2]==num[j+n][3]+num[j+n][4]+num[j+n][5])
63                 G[i].push_back(j+n);
64             if(num[i][3]+num[i][4]+num[i][5]==num[j+n][0]+num[j+n][1]+num[j+n][2])
65                 G[i].push_back(j+n);
66         }
67     }
68     cout<<solve(n)<<endl;
69     for(int i=n+1; i<=n+m; i++)
70     {
71         if(cy[i]==-1)continue;
72         if(num[cy[i]][0]+num[cy[i]][1]+num[cy[i]][2]==num[i][3]+num[i][4]+num[i][5])
73             cout<<"AT"<<" "<<num[cy[i]]<<" "<<num[i]<<endl;
74         else if(num[i][0]+num[i][1]+num[i][2]==num[cy[i]][3]+num[cy[i]][4]+num[cy[i]][5])
75             cout<<"TA"<<" "<<num[i]<<" "<<num[cy[i]]<<endl;
76     }
77     return 0;
78 }

 

codeforces gym101243 A C D E F G H J

原文:http://www.cnblogs.com/hsd-/p/7123982.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!