zoukankan      html  css  js  c++  java
  • CodeForces Round #303 Div. 2

    A. Toy Cars

    1s, 256Mb

    Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.

    There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the і-th row and j-th column that describes the result of the collision of the і-th and the j-th car:

    •  - 1: if this pair of cars never collided.  - 1 occurs only on the main diagonal of the matrix.
    • 0: if no car turned over during the collision.
    • 1: if only the i-th car turned over during the collision.
    • 2: if only the j-th car turned over during the collision.
    • 3: if both cars turned over during the collision.

    Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task?

    Input

    The first line contains integer n (1 ≤ n ≤ 100) — the number of cars.

    Each of the next n lines contains n space-separated integers that determine matrix A.

    It is guaranteed that on the main diagonal there are  - 1, and  - 1 doesn't appear anywhere else in the matrix.

    It is guaranteed that the input is correct, that is, if Aij = 1, then Aji = 2, if Aij = 3, then Aji = 3, and if Aij = 0, then Aji = 0.

    Output

    Print the number of good cars and in the next line print their space-separated indices in the increasing order.

    Sample test(s)
    input
    3
    -1 0 0
    0 -1 1
    0 2 -1
    output
    2
    1 3
    input
    4
    -1 3 3 3
    3 -1 3 3
    3 3 -1 3
    3 3 3 -1
    output
    0

     【题解】

    随便搞搞啊= =并不难

    我太弱了只会水题= =

     1 #include<stdio.h>
     2 #include<string.h>
     3 using namespace std;
     4 bool k[110];
     5 int a[110][110],n;
     6 void g(int &xx) {
     7     int x=0;
     8     int f=1; char ch=getchar();
     9     while(ch<'0' || ch>'9') {if(ch=='-') f=-1; ch=getchar(); }
    10     while(ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    11     xx=x*f;
    12 }
    13 int main() {
    14     memset(k,1,sizeof(k));
    15     g(n);
    16     for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) g(a[i][j]);
    17     for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) {
    18         if(a[i][j]==-1||a[i][j]==0) continue;
    19         if(a[i][j]==1) k[i]=0;
    20         else if(a[i][j]==2) k[j]=0;
    21         else k[i]=k[j]=0;
    22     }
    23     int ans=0;
    24     for (int i=1;i<=n;++i)
    25         ans+=k[i];
    26     printf("%d
    ",ans);
    27     for (int i=1;i<=n;++i) if(k[i]) printf("%d ",i);
    28     return 0;
    29 }
    View Code
     

    B. Equidistant String

    1s, 256Mb

    Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:

    We will define the distance between two strings s and t of the same length consisting of digits zero and one as the number of positions i, such that si isn't equal to ti.

    As besides everything else Susie loves symmetry, she wants to find for two strings s and t of length n such string p of length n, that the distance from p to s was equal to the distance from p to t.

    It's time for Susie to go to bed, help her find such string p or state that it is impossible.

    Input

    The first line contains string s of length n.

    The second line contains string t of length n.

    The length of string n is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one.

    Output

    Print a string of length n, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes).

    If there are multiple possible answers, print any of them.

    Sample test(s)
    input
    0001
    1011
    output
    0011
    input
    000
    111
    output
    impossible
    Note

    In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101.

    【题解】两个01串,求一个串异或两个串所获得的1一样多。

     1 #include<stdio.h>
     2 #include<string>
     3 #include<iostream>
     4 using namespace std;
     5 string s,t;
     6 int main() {
     7     cin>>s>>t;
     8     int l=s.length();
     9     int c=0;
    10     for (int i=0;i<l;++i)
    11         if(s[i]!=t[i]) c++;
    12     if(c&1) {
    13         printf("impossible
    ");
    14         return 0;
    15     }
    16     bool flag=0;
    17     for (int i=0;i<l;++i)
    18         if(s[i]==t[i]) printf("%c",s[i]);
    19         else {
    20             if(!flag) printf("%c",s[i]);
    21             else printf("%c",t[i]);
    22             flag^=1;
    23         }
    24     printf("
    ");
    25     return 0;
    26 }
    View Code

    D. Queue

    1s, 256Mb

    Little girl Susie went shopping with her mom and she wondered how to improve service quality.

    There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed.

    Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.

    Input

    The first line contains integer n (1 ≤ n ≤ 105).

    The next line contains n integers ti (1 ≤ ti ≤ 109), separated by spaces.

    Output

    Print a single number — the maximum number of not disappointed people in the queue.

    Sample test(s)
    input
    5
    15 2 1 5 3
    output
    4
    Note

    Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.

    【题解】

    就是一道简单题。。。

    sort后贪心即可= =

     1 #include<stdio.h>
     2 #include<algorithm>
     3 using namespace std;
     4 int main() {
     5     int n,a[100010];
     6        scanf("%d",&n);
     7     for (int i=1;i<=n;++i)scanf("%d",&a[i]);
     8     sort(a+1,a+n+1);
     9     int s=0,ss=0;
    10     for (int i=1;i<=n;++i)
    11         if(s<=a[i]) {++ss;s+=a[i];}
    12     printf("%d
    ",ss);
    13     return 0;
    14 }
    View Code

    =========================================

    就只会这三题TAT,后面有空补完题......

    打Vitual Test.....

  • 相关阅读:
    pygrib的操作用法
    pythonista安装stash
    关于crontab运行python脚本不生效,但是手动执行却正常的问题
    windows下使用tensorboard注意事项
    请教tornadomeet大神Kinect+OpenNI学习笔记之8(Robert Walter手部提取代码的分析)(OpenNI2、NiTE2改编)
    CCV 调试 (一)
    数字图像处理第二次作业
    yangyangcv的OpenNI驱动玩隔空触摸源代码分析
    openFrameworks 学习笔记(一)
    关于error LNK2001: unresolved external symbol "__declspec(dllimport) public
  • 原文地址:https://www.cnblogs.com/TonyNeal/p/cfr303d2_1.html
Copyright © 2011-2022 走看看