• Codeforces Round #545 (Div. 2)(B. Circus)


    题目链接:http://codeforces.com/contest/1138/problem/B

    题目大意:贼绕口的题目,就是给你两个字符串s1,s2,然后每一个人代表一列,第一列代表技能一每个人是否会,第二列代表技能2是否每个人会。然后1代表当前的技能这个人会,0代表不会。

    然后让你安排这个n个人去两场演出,要求 第一场的技能一会的人数和第二场技能二会的人数是相同的,然后问你是否有合法的请况,如果有输出第一场派谁去。如果没有,输出-1.

    具体思路:(首先四个for循环是肯定会超时的)。我们枚举1 1 和1 0 这两种情况。因为最终每个人都要上场,所以我们确定出第一场中派哪些人去。具体的判断方法:计算当前情况下,第二场中会技能二的人比当前的第一场中会技能一的人多多少人。然后再看一下第一场中会技能一的能不能补出这个空就行了,如果有就输出合法情况。

    AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int maxn = 2e5+100;
     4 vector<int>a;
     5 vector<int>b;
     6 vector<int>c;
     7 vector<int>d;
     8 char str1[maxn],str2[maxn];
     9 int main()
    10 {
    11     int n;
    12     scanf("%d",&n);
    13     cin>>str1+1;
    14     cin>>str2+1;
    15     for(int i=1;i<=n;i++){
    16     if(str1[i]=='1'&&str2[i]=='1')a.push_back(i);
    17     else if(str1[i]=='1'&&str2[i]=='0')b.push_back(i);
    18     else if(str1[i]=='0'&&str2[i]=='1')c.push_back(i);
    19     else if(str1[i]=='0'&&str2[i]=='0')d.push_back(i);
    20     }
    21     for(int i=0;i<=b.size();i++){
    22     for(int j=0;j<=a.size();j++){
    23     int tmp=a.size()+c.size()-j*2-i;
    24     if(tmp>=0&&tmp<=c.size()){
    25     int tmp1=i+j+tmp;
    26     int tmp2=n/2-tmp1;
    27     if(tmp2>=0&&tmp2<=d.size()){
    28     for(int k=0;k<tmp2;k++)printf("%d ",d[k]);
    29     for(int k=0;k<i;k++)printf("%d ",b[k]);
    30     for(int k=0;k<j;k++)printf("%d ",a[k]);
    31     for(int k=0;k<tmp;k++)printf("%d ",c[k]);
    32     return 0;
    33     }
    34     }
    35     }
    36     }
    37     printf("-1
    ");
    38 }
  • 相关阅读:
    Cognitive Radio Cognitive Network Simulator (NS3 based)
    RCU(Read-Copy Update)synchronize原理分析
    英雄黑客:一个试图提高物联网安全性的“义务警员”
    Android NDK放弃GCC,全面转向Clang
    Why is FreeBSD deprecating GCC in favor of Clang/LLVM?
    (Low Level Virtual Machine) LLVM 与 Clang介绍
    RMS谈GCC、LLVM和Copyleft
    LLVM和Clang背后的故事
    FEP: 测试 lineage, 获得 CPU, MEMORY 统计信息
    以wifi-example-sim.cc为例说明NS3统计数据模型
  • 原文地址:https://www.cnblogs.com/letlifestop/p/10512307.html
Copyright © 2020-2023  润新知