zoukankan      html  css  js  c++  java
  • Codeforces Round #205 (Div. 2)

    A

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<stdlib.h>
     6 #include<vector>
     7 using namespace std;
     8 int a[110];
     9 int main()
    10 {
    11     int i,j,n,u,v;
    12     int s1=0,s2=0,num=0;
    13     scanf("%d",&n);
    14     for(i = 1; i <= n ; i++)
    15     {
    16         scanf("%d%d",&u,&v);
    17         if((u%2==0&&v%2!=0)||(u%2!=0&&v%2==0))
    18         num++;
    19         s1+=u;
    20         s2+=v;
    21     }
    22     if(s1%2==0&&s2%2==0)
    23     {
    24         printf("0
    ");
    25     }
    26     else if(s1%2!=0&&s2%2!=0)
    27     {
    28         if(num)
    29         printf("1
    ");
    30         else
    31         printf("-1
    ");
    32     }
    33     else
    34     printf("-1
    ");
    35     return 0;
    36 }
    View Code

    B 构造一下。。乱弄了下

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<stdlib.h>
     6 #include<vector>
     7 using namespace std;
     8 #define N 210
     9 int n,a[N],f[N],o[N];
    10 int main()
    11 {
    12     int i,j;
    13     scanf("%d",&n);
    14     for(i =1; i <= 2*n ; i++)
    15     {
    16         scanf("%d",&a[i]);
    17         f[a[i]]++;
    18     }
    19     int s1=0,s2=0,num=0;
    20     for(i = 10 ; i <= 99 ; i++)
    21     if(f[i]>=2)
    22     {
    23         if(f[i]%2==0)
    24         {
    25             s1+=f[i]/2-1;
    26         }
    27         else
    28         {
    29             s1+=f[i]/2-1;
    30             s2++;
    31         }
    32     }
    33     else if(f[i]==1)
    34     num++;
    35     int k1 = s2/2,k2 = n-s1-s2/2;
    36     int ans = (n-s1-s2/2)*(n-s1-(s2-s2/2));
    37     num = (num+1)/2;
    38    // printf("")
    39     for(i = 1 ; i <= 2*n ; i++)
    40     {
    41         if(f[a[i]]==1)
    42         {
    43             o[i] = 1;
    44             num--;
    45         }
    46         if(num==0)
    47         break;
    48     }
    49     for(i = 1; i <= 2*n ; i++)
    50     {
    51         if(f[a[i]]>=2)
    52         {
    53             int kk;
    54             if(k1&&f[a[i]]%2!=0)
    55             {
    56                 kk = f[a[i]]/2+1;
    57                 k1--;
    58             }
    59             else
    60             kk = f[a[i]]/2;
    61             for(j = 1; j <= 2*n ; j++)
    62             {
    63                 if(a[j]==a[i])
    64                 {
    65                     kk--;
    66                     o[j] = 1;
    67                 }
    68                 if(kk==0)
    69                 break;
    70             }
    71             f[a[i]] = 0;
    72         }
    73     }
    74     printf("%d
    ",ans);
    75     for(i = 1; i < 2*n ; i++)
    76     if(o[i]==1)
    77     printf("1 ");
    78     else
    79     printf("2 ");
    80     if(o[2*n]==1)
    81     printf("1
    ");
    82     else
    83     printf("2
    ");
    84     return 0;
    85 }
    View Code

    C  枚举1的位置 变为0后 后面全取1  一个很2的错误WA了2 次

     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<stdlib.h>
     6 #include<vector>
     7 using namespace std;
     8 #define N 100010
     9 #define LL __int64
    10 int a[N];
    11 LL sum[N];
    12 char s[N];
    13 int main()
    14 {
    15     int i,j,n;
    16     scanf("%d",&n);
    17     for(i = 0; i < n ; i++)
    18     scanf("%d",&a[i]);
    19     cin>>s;
    20     int k=-1;
    21     LL ss=0,maxz=0;
    22     for(i = 0 ; i < n ;i++)
    23     {
    24         if(s[i]=='1')
    25         {
    26             ss+=a[i];
    27             if(i==0)
    28             sum[i] = a[i];
    29             else
    30             sum[i]=sum[i-1]+a[i];
    31             k = i;
    32         }
    33         else
    34         if(i!=0)
    35         sum[i] = sum[i-1];
    36     }
    37     if(k==-1)
    38     printf("0
    ");
    39     else
    40     {
    41         maxz = max(maxz,ss);
    42         int tsum=0;
    43         for(i = 0 ; i <= k ; i++)
    44         {
    45             if(s[i]=='1')
    46             {
    47                 maxz = max(sum[k]-sum[i]+tsum,maxz);
    48             }
    49             tsum+=a[i];
    50         }
    51         printf("%I64d
    ",maxz);
    52     }
    53     return 0;
    54 }
    View Code
  • 相关阅读:
    Android Hal 分析
    Android JNI 使用的数据结构JNINativeMethod详解
    MTK GPIO 一些理解
    DEVICE_ATTR
    DEVICE_ATTR
    内核驱动中常见的miscdevice、platform_device、platform_driver
    DEVICE_ATTR实例分析
    虚拟机安装Ubuntu14.04打开FireFox提示Server not found
    Android编译系统中的Kconfig,Makefile,.config编译系统浅析
    几款在线脑图制作工具
  • 原文地址:https://www.cnblogs.com/shangyu/p/3363573.html
Copyright © 2011-2022 走看看