码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces #368

时间:2016-08-21 13:39:08      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

Problem A  Brain‘s Photos

题目大意

  n行m列的矩形,每个格子有一种颜色。如果含有C、M、Y则输出#Color,否则输出#Black&White。

解题分析

  = =

参考程序

技术分享
 1 #include <map>
 2 #include <set>
 3 #include <stack>
 4 #include <queue>
 5 #include <cmath>
 6 #include <ctime>
 7 #include <string>
 8 #include <vector>
 9 #include <cstdio>
10 #include <cstdlib>
11 #include <cstring>
12 #include <cassert>
13 #include <iostream>
14 #include <algorithm>
15 #pragma comment(linker,"/STACK:102400000,102400000")
16 using namespace std;
17 
18 #define V 100008             
19 #define E 2000008    
20 #define LL long long
21 #define lson l,m,rt<<1
22 #define rson m+1,r,rt<<1|1 
23 #define clr(x,v) memset(x,v,sizeof(x));
24 #define bitcnt(x) __builtin_popcount(x)
25 #define rep(x,y,z) for (int x=y;x<=z;x++)
26 #define repd(x,y,z) for (int x=y;x>=z;x--)
27 const int mo  = 1000000007;
28 const int inf = 0x3f3f3f3f;
29 const int INF = 2000000000;
30 /**************************************************************************/ 
31 int n,m;
32 char s[10];
33 int main(){
34     scanf("%d%d",&n,&m);
35     int ok=1;
36     for (int i=1;i<=n;i++)
37         for (int j=1;j<=m;j++)
38         {
39             scanf("%s",s);
40             if (s[0]==C || s[0]==M || s[0]==Y) ok=0;
41         }
42     if (ok) printf("#Black&White\n"); else printf("#Color\n");
43 }
View Code

Problem B  Bakery

题目大意

  给一张n个点m条边有边权的无向图,有k个点是仓库。要求在某个非仓库点开面包店,使得其与最近的仓库的距离最小。

解题分析

  枚举每个仓库点,再遍历其相邻点,统计对答案的贡献。

  时间复杂度O(E)

参考程序

技术分享
 1 #include <map>
 2 #include <set>
 3 #include <stack>
 4 #include <queue>
 5 #include <cmath>
 6 #include <ctime>
 7 #include <string>
 8 #include <vector>
 9 #include <cstdio>
10 #include <cstdlib>
11 #include <cstring>
12 #include <cassert>
13 #include <iostream>
14 #include <algorithm>
15 #pragma comment(linker,"/STACK:102400000,102400000")
16 using namespace std;
17 
18 #define V 100008             
19 #define E 200008    
20 #define LL long long
21 #define lson l,m,rt<<1
22 #define rson m+1,r,rt<<1|1 
23 #define clr(x,v) memset(x,v,sizeof(x));
24 #define bitcnt(x) __builtin_popcount(x)
25 #define rep(x,y,z) for (int x=y;x<=z;x++)
26 #define repd(x,y,z) for (int x=y;x>=z;x--)
27 const int mo  = 1000000007;
28 const int inf = 0x3f3f3f3f;
29 const int INF = 2000000000;
30 /**************************************************************************/ 
31 
32 int n,m,k;
33 
34 struct line{
35     int u,v,w,nt;
36 }eg[E];
37 int lt[V],sum=1;
38 int ok[V];
39 void add(int u,int v,int w){
40     eg[++sum].u=u; eg[sum].v=v; eg[sum].w=w; eg[sum].nt=lt[u]; lt[u]=sum;
41 }
42 int main(){
43     clr(ok,0);
44     scanf("%d%d%d",&n,&m,&k);
45     rep(i,1,m){
46         int u,v,w;
47         scanf("%d %d %d",&u,&v,&w);
48         add(u,v,w);
49         add(v,u,w);
50     }
51     rep(i,1,k){
52         int x;
53         scanf("%d",&x);
54         ok[x]=1;
55     }
56     int ans=INF;
57     rep(u,1,n)
58         if (ok[u]){
59             for (int i=lt[u];i;i=eg[i].nt){
60                 int v=eg[i].v;
61                 if (!ok[v]) ans=min(ans,eg[i].w);
62             }
63         }
64     printf("%d\n",ans==INF?-1:ans);
65 }
View Code

Problem C  Pythagorean Triples

题目大意

  给定一个数n,要求输出两个数m,k,使得n、m、k构成一组勾股数。

  (n<=10^9,m,k<=10^10^18)

解题分析

  对于1,2特判一下无解。

  对于2^i的数字,等于将3,4,5这3个数扩大若干倍。

  对于奇数x,可以构造出(x^2+1)/2 , (x^2-1)/2 满足条件。

  对于偶数x,可以将其经过若干次除2后变成奇数,再扩大回去。

参考程序

技术分享
 1 #include <map>
 2 #include <set>
 3 #include <stack>
 4 #include <queue>
 5 #include <cmath>
 6 #include <ctime>
 7 #include <string>
 8 #include <vector>
 9 #include <cstdio>
10 #include <cstdlib>
11 #include <cstring>
12 #include <cassert>
13 #include <iostream>
14 #include <algorithm>
15 #pragma comment(linker,"/STACK:102400000,102400000")
16 using namespace std;
17 
18 #define N 508             
19 #define M 50008    
20 #define LL long long
21 #define lson l,m,rt<<1
22 #define rson m+1,r,rt<<1|1 
23 #define clr(x,v) memset(x,v,sizeof(x));
24 #define bitcnt(x) __builtin_popcount(x)
25 #define rep(x,y,z) for (int x=y;x<=z;x++)
26 #define repd(x,y,z) for (int x=y;x>=z;x--)
27 const int mo  = 1000000007;
28 const int inf = 0x3f3f3f3f;
29 const int INF = 2000000000;
30 /**************************************************************************/ 
31 
32 LL x;
33 
34 int main(){
35     scanf("%I64d",&x);
36     int num=0;
37     while (x % 2 ==0){
38         if (x==4) break;
39         num++;
40         x/=2;
41     }
42     if (x==4){
43         LL y=3,z=5;
44         while (num){
45             y*=2;
46             z*=2;
47             num--;
48         }
49         printf("%I64d %I64d\n",y,z);
50         return 0;
51     }
52     LL y=(x*x+1)/2,z=y-1;
53     if (z>0){
54         while (num){
55             y*=2;
56             z*=2;
57             num--;
58         }
59         printf("%I64d %I64d\n",z,y);
60     }
61     else printf("-1\n");
62 
63 }
View Code

Problem D  Persistent Bookcase

 

codeforces #368

标签:

原文地址:http://www.cnblogs.com/rpSebastian/p/5792495.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!