codeforces #368

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 }

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 }

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 }

Problem D  Persistent Bookcase

时间: 2024-08-13 19:04:18

codeforces #368的相关文章

CodeForces #368 div2 D Persistent Bookcase DFS

题目链接:D Persistent Bookcase 题意:有一个n*m的书架,开始是空的,现在有k种操作: 1 x y 这个位置如果没书,放书. 2 x y 这个位置如果有书,拿走. 3 x 反转这一行,即有书的位置拿走,没书的位置放上书. 4 x 返回到第x步操作之后的书架. 现在给出q个操作,询问每次操作之后书架上书的数量. 思路: 开始没有思路.后来被告知dfs. [词不达意.参考:http://blog.csdn.net/zyjhtutu/article/details/5227949

Codeforces Round #368 (Div. 2) Brain&#39;s Photos

Brain's Photos Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos

Codeforces Round #368 (Div. 2) Pythagorean Triples

Pythagorean Triples Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths

Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学

给定一个直角三角形的一边长度.问是否存在一个直角三角形,使得它满足有一边的长度是x 当x=1.2的时候是无解的,可以暴力打表看看. 注意到,相邻的两个数的平方的差值是奇数 x^2 - (x-1)^2 = 2*x-1 间隔为2的两个数的平方的差值是偶数 (x+1)^2 - (x-1)^2 = 4*x 这样就可以分类讨论了. 把n永远当成是指角边就OK #include <cstdio> #include <cstdlib> #include <cstring> #incl

Codeforces Round #368 (Div. 2)

A. Brain's Photos 题意: 给你一个n*m的字符矩阵,如果字符中出现'C', 'M', 'Y'这三个中的任何一个就输出"#Color";否则输出"#Black&White". 代码如下: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <fstream> 5 #include <ctime&

Codeforces Round #368 (Div. 2) Bakery

Bakery Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities. To bake muffins in her bakery, Masha needs to establish flour supply

Codeforces Round #368 (Div. 2) ABCD

A. Brain's Photos 题解: 水得不要不要的 代码: #include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define LL long long #define CLR(x) memset(x,0,sizeof x) #define MC(x,y) memcpy(x,y,sizeof(x)

Codeforces 707 C. Pythagorean Triples(找规律)——Codeforces Round #368 (Div. 2)

传送门 Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding t

Codeforces Round #368 (Div. 2) A

Description Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are