zoukankan      html  css  js  c++  java
  • Codeforces707Div2

    A

    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 on the film (because you can specify the hashtag #film for such).

    Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!

    As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.

    Photo can be represented as a matrix sized n × m, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:

    • 'C' (cyan)
    • 'M' (magenta)
    • 'Y' (yellow)
    • 'W' (white)
    • 'G' (grey)
    • 'B' (black)

    The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.

    Input

    The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100) — the number of photo pixel matrix rows and columns respectively.

    Then n lines describing matrix rows follow. Each of them contains m space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.

    Output

    Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.

    输入一个颜色矩阵问,是不是黑白的.

    傻逼题,不解释

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #include<string>
     4 #include<string.h>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<queue>
     8 #include<math.h>
     9 #include<vector>
    10 #include<map>
    11 #include<set>
    12 #define il inline
    13 #define re register
    14 using namespace std;
    15 int n,m;
    16 int main(){
    17     scanf("%d%d",&n,&m);
    18     char str[101];
    19     for(int i=1;i<=n;i++){
    20         for(int j=1;j<=m;j++){
    21             scanf("%s",str);
    22             if(str[0]=='C'||str[0]=='M'||str[0]=='Y'){
    23                 cout<<"#Color";return 0;
    24             }
    25         }
    26     }
    27     cout<<"#Black&White";
    28     return 0;
    29 }

    B

    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 from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.

    Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.

    Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).

    Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount.

    Input

    The first line of the input contains three integers nm and k (1 ≤ n, m ≤ 10^5, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively.

    Then m lines follow. Each of them contains three integers uv and l (1 ≤ u, v ≤ n1 ≤ l ≤ 10^9, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers .

    If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input.

    Output

    Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line.

    If the bakery can not be opened (while satisfying conditions) in any of the n cities, print  - 1 in the only line.

    无向图图中有特殊点,问特殊点到非特殊点的最短距离

    显然这是链接两个点集的一条边

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #include<string>
     4 #include<string.h>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<queue>
     8 #include<math.h>
     9 #include<vector>
    10 #include<map>
    11 #include<set>
    12 #define il inline
    13 #define re register
    14 using namespace std;
    15 struct edge{int next,to,val;
    16 } e[200001];
    17 int n,m,k,a[200001],ans=(1<<30),M,g[200001];
    18 il void addedge(int x,int y,int z){
    19     e[++M]=(edge){g[x],y,z};g[x]=M;
    20 }
    21 int main(){
    22     scanf("%d%d%d",&n,&m,&k);
    23     for(int i=1,x,y,z;i<=m;i++){
    24         scanf("%d%d%d",&x,&y,&z);
    25         addedge(x,y,z);
    26         addedge(y,x,z);
    27     }
    28     for(int i=1,x;i<=k;i++){
    29         scanf("%d",&x);a[x]=1;
    30     }
    31     for(int i=1;i<=n;i++) if(!a[i]){
    32         for(int j=g[i];j;j=e[j].next) if(a[e[j].to]){
    33             ans=min(ans,e[j].val);
    34         }
    35     }
    36     if(ans<(1<<30)) cout<<ans;
    37     else cout<<"-1";
    38     return 0;
    39 }

    C

    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 to triple. Such triples are calledPythagorean triples.

    For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.

    Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.

    Katya had no problems with completing this task. Will you do the same?

    Input

    The only line of the input contains single integer n (1 ≤ n ≤ 10^9) — the length of some side of a right triangle.

    Output

    Print two integers m and k (1 ≤ m, k ≤ 10^18), such that nm and k form a Pythagorean triple, in the only line.

    In case if there is no any Pythagorean triple containing integer n, print  - 1 in the only line. If there are many answers, print any of them.

    输入直角三角形的一条边,构造其它两条边,使得能构成一个直角三角形。

    如果n是一个奇数 三角形分别是 n (n^2-1)/2 (n^2+1)/2

    如果n是一个偶数 三角形分别是 n (n*n/4-1) (n*n/4+1)

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #include<string>
     4 #include<string.h>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<queue>
     8 #include<math.h>
     9 #include<vector>
    10 #include<map>
    11 #include<set>
    12 #define il inline
    13 #define re register
    14 using namespace std;
    15 long long n;
    16 int main(){
    17     cin>>n;
    18     if(n<3){
    19         cout<<"-1";
    20     }
    21     else if(n&1){
    22         cout<<(n*n-1)/2<<" "<<(n*n+1)/2;
    23     }
    24     else{
    25         n/=2;
    26         cout<<(n*n-1)<<" "<<(n*n+1);
    27     }
    28     return 0;
    29 }

    D

    Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified.

    After reaching home Alina decided to invent her own persistent data structure. Inventing didn't take long: there is a bookcase right behind her bed. Alina thinks that the bookcase is a good choice for a persistent data structure. Initially the bookcase is empty, thus there is no book at any position at any shelf.

    The bookcase consists of n shelves, and each shelf has exactly m positions for books at it. Alina enumerates shelves by integers from 1to n and positions at shelves — from 1 to m. Initially the bookcase is empty, thus there is no book at any position at any shelf in it.

    Alina wrote down q operations, which will be consecutively applied to the bookcase. Each of the operations has one of four types:

    • i j — Place a book at position j at shelf i if there is no book at it.
    • i j — Remove the book from position j at shelf i if there is a book at it.
    • i — Invert book placing at shelf i. This means that from every position at shelf i which has a book at it, the book should be removed, and at every position at shelf i which has not book at it, a book should be placed.
    • k — Return the books in the bookcase in a state they were after applying k-th operation. In particular, k = 0 means that the bookcase should be in initial state, thus every book in the bookcase should be removed from its position.

    After applying each of operation Alina is interested in the number of books in the bookcase. Alina got 'A' in the school and had no problem finding this values. Will you do so?

    Input

    The first line of the input contains three integers nm and q (1 ≤ n, m ≤ 10^3, 1 ≤ q ≤ 10^5) — the bookcase dimensions and the number of operations respectively.

    The next q lines describes operations in chronological order — i-th of them describes i-th operation in one of the four formats described in the statement.

    It is guaranteed that shelf indices and position indices are correct, and in each of fourth-type operation the number k corresponds to some operation before it or equals to 0.

    Output

    For each operation, print the number of books in the bookcase after applying it in a separate line. The answers should be printed in chronological order.

    要求你实现一个矩阵,使得其满足以下操作

    1. 将给定矩阵位置的值改为1

    2. 将给定矩阵位置的值改为0

    3. 翻转这个矩阵的一行

    4. 把矩阵恢复到第k次操作之后

    离线操作,将版本建成一棵树,每次暴力处理即可

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #include<string>
     4 #include<string.h>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<queue>
     8 #include<math.h>
     9 #include<vector>
    10 #include<map>
    11 #include<set>
    12 #define il inline
    13 #define re register
    14 using namespace std;
    15 const int N=1000001;
    16 int n,m,Q,k[N],x[N],y[N],tag[1001],a[1001][1001],sum[1001],ans,fin[N];
    17 vector<int> g[N];
    18 il void flip(int x){
    19     tag[x]^=1;
    20     ans+=m-sum[x]-sum[x];
    21     sum[x]=m-sum[x];
    22 }
    23 il void dfs(re int h){
    24     fin[h]=ans;
    25     if(k[h+1]!=4&&h<Q){
    26         if(k[h+1]==3){
    27             flip(x[h+1]);
    28             dfs(h+1);
    29             flip(x[h+1]);
    30         }
    31         else if(k[h+1]==1){
    32             if(a[x[h+1]][y[h+1]]^tag[x[h+1]]==0){
    33                 sum[x[h+1]]++;ans++;
    34                 a[x[h+1]][y[h+1]]^=1;
    35                 dfs(h+1);
    36                 a[x[h+1]][y[h+1]]^=1;
    37                 sum[x[h+1]]--;ans--;
    38             }
    39             else dfs(h+1);
    40         }
    41         else if(k[h+1]==2){
    42             if(a[x[h+1]][y[h+1]]^tag[x[h+1]]==1){
    43                 sum[x[h+1]]--;ans--;
    44                 a[x[h+1]][y[h+1]]^=1;
    45                 dfs(h+1);
    46                 a[x[h+1]][y[h+1]]^=1;
    47                 sum[x[h+1]]++;ans++;
    48             }
    49             else dfs(h+1);
    50         }
    51     }
    52     for(re int i=g[h].size()-1;i>=0;i--){
    53     //    cout<<h<<" "<<"=="<<ans<<endl;
    54         dfs(g[h][i]);
    55     }
    56 
    57 }
    58 int main(){
    59     scanf("%d%d%d",&n,&m,&Q);
    60     for(int i=1;i<=Q;i++){
    61         scanf("%d%d",&k[i],&x[i]);
    62         if(k[i]==4){
    63             g[x[i]].push_back(i);
    64         }
    65         else{
    66             if(k[i]<3) scanf("%d",&y[i]);
    67         }
    68     }
    69     dfs(0);
    70     for(int i=1;i<=Q;i++)
    71         printf("%d
    ",fin[i]);
    72     return 0;
    73 }
  • 相关阅读:
    AcWing 125. 耍杂技的牛
    AcWing 148. 合并果子
    AcWing 907. 区间覆盖
    AcWing 908. 最大不相交区间数量
    AcWing 906. 区间分组
    AcWing 905. 区间选点
    AcWing 285. 没有上司的舞会
    AcWing 1049. 大盗阿福
    AcWing 901. 滑雪
    AcWing 91. 最短Hamilton路径
  • 原文地址:https://www.cnblogs.com/ExiledPoet/p/5795240.html
Copyright © 2011-2022 走看看