# CF #310 (Div. 2)

A. Case of the Zeros and Ones

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<time.h>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
#include<map>
//#define ONLINE_JUDGE
#define eps 1e-10
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c)scanf("%d%d%d",&a,&b,&c)
#define for1(i,a,b) for(int i=(a);i<b;i++)
#define for2(i,a,b) for(int i=(a);i<=b;i++)
#define for3(i,a,b)for(int i=(b);i>=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
#define ll __int64
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
int n,m;
int s;
#define N 200010
char ch[N];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
while(scanf("%d",&n)!=EOF){
sfs(ch);
int zero=0,one=0;
for(int i=0;i<n;i++){
if(ch[i] == '0') zero++;
else
one++;
}
printf("%d\n",n-Min(zero,one)*2);
}
return 0;
}

B. Case of Fake Numbers

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<time.h>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
#include<map>
//#define ONLINE_JUDGE
#define eps 1e-10
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c)scanf("%d%d%d",&a,&b,&c)
#define for1(i,a,b) for(int i=(a);i<b;i++)
#define for2(i,a,b) for(int i=(a);i<=b;i++)
#define for3(i,a,b)for(int i=(b);i>=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
#define ll __int64
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
int n,m;
int s;
#define N 200010
int a[1010];
bool check(){
for(int i=0;i<n;i++){
if(a[i]!=i)return false;
}
return true;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++)
sf(a[i]);
while(a[0]){
int s=1;
for(int i=0;i<n;i++){
a[i] += s;
if(a[i] < 0)
a[i] = n-1;
if(a[i] >= n)
a[i] = 0;
s = -s;
}
}
if(check())
printf("Yes\n");
else
printf("No\n");
}
return 0;
}

C. Case of Matryoshkas
C 题也是只要读懂就不难。。刚开始没读懂，错了一发。。其实只要统计从1开始的那一行，最大能够连续几个，其他行都要全部拆分，然后再依次序套上去。

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<time.h>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
#include<map>
//#define ONLINE_JUDGE
#define eps 1e-10
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c)scanf("%d%d%d",&a,&b,&c)
#define for1(i,a,b) for(int i=(a);i<b;i++)
#define for2(i,a,b) for(int i=(a);i<=b;i++)
#define for3(i,a,b)for(int i=(b);i>=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
#define ll __int64
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
int n,m;
int s;
#define N 200010
int a[1010];
//vector<int> v[100005];
pair<int,int> pos[100005];
int size[100005];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
int k;
while(scanf("%d%d",&n,&k)!=EOF){
//      for(int i=0;i<n;i++)
//          v[i].clear();
memset(pos,-1,sizeof pos);
memset(size,0,sizeof size);
int x;
for(int i=0;i<k;i++){
sf(m);
for(int j=0;j<m;j++){
sf(x);
//              v[i].push_back(x);
pos[x].first = i;
pos[x].second = j;
}
size[i] = m;
}
int ans = 0;
int kk = 0;
int tmpx = pos[1].first;
int tmpy = pos[1].second;
kk = 0;
int p=2;
while(p<=n&&pos[p].first == tmpx && pos[p].second == tmpy+1){
tmpy = pos[p].second;
p++;
}
kk += (size[tmpx]-1-(p-2));//统计1的那一行被拆分成了几个模块
ans += kk+kk; //第一行重新组合需要的步骤数
for(int i=0;i<k;i++){ //除了第一行以外其他行需要拆分和重新组合的步骤数
if(i == tmpx) continue;
ans += (size[i]-1)+size[i];
}
printf("%d\n",ans);
}
return 0;
}

D. Case of Fugitive
D题其实也不算难。题目大意就是有n条线段，它们各自覆盖一个取余，然后他们之间有n-1端空白未被覆盖，现在有m段桥，问你是否能从中选出n-1条桥，使得未被覆盖的区域被覆盖且只被覆盖一次。

#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<time.h>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
#include<map>
//#define ONLINE_JUDGE
#define eps 1e-10
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,c)scanf("%d%d%d",&a,&b,&c)
#define for1(i,a,b) for(int i=(a);i<b;i++)
#define for2(i,a,b) for(int i=(a);i<=b;i++)
#define for3(i,a,b)for(int i=(b);i>=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
#define ll __int64
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
int n,m;
#define N 200010
struct Seg{
int id;
ll l,r;
bool operator < (const Seg &x) const{ //优先队列，使得其按照右边界从小到大进行排序
return r>x.r;
}
}a[N];
struct Bridge{
int id;
ll len;
}bri[N];
bool cmp(Seg x,Seg y){
return x.l<y.l;
}
bool cmp1(Bridge x,Bridge y){
return x.len<y.len;
}
int ans[N];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif
int k;
while(scanf("%d%d",&n,&m)!=EOF){
ll pl,pr;
ll nl,nr;
scanf("%I64d%I64d",&pl,&pr);
n--;
for(int i=0;i<n;i++){
scanf("%I64d%I64d",&nl,&nr);
a[i].id=i;
a[i].l = nl-pr; //左边界长度
a[i].r = nr-pl; //右边界长度
pl = nl;
pr = nr;
}
for(int i=0;i<m;i++){
scanf("%I64d",&bri[i].len);
bri[i].id = i+1;
}
sort(bri,bri+m,cmp1);
sort(a,a+n,cmp);
priority_queue<Seg> q;
k=0;
int num=0;
for(int i=0;i<m;i++){
while(k<n && a[k].l<=bri[i].len){ //第i条桥大于等于第k个区间
q.push(a[k]);
k++;
}
if(q.empty() || q.top().r<bri[i].len) //如果q为空 或者 符合条件的最小的右边界小于当前桥的长度，那么该区间不可覆盖
continue;
ans[q.top().id] = bri[i].id; //记录每个空白区间被哪个标号的桥所覆盖
q.pop();
num++;
}
//      printf("%d\n",num);
if(num != n)      //n在上面有n--，其实这里相当于原来的n-1
printf("No\n");
else{
printf("Yes\n");
for(int i=0;i<n;i++) printf("%d%c",ans[i],i+1==n?'\n':' ');
}
}
return 0;
}


#### Codeforces Round #459 (Div. 2)The Monster[匹配问题]

2018-01-30 15:20:19

#### CF-Codeforces Round #485 (Div. 2)-E-Petr and Permutations

2018-05-30 17:33:35

#### Codeforces Round #294 (Div. 2) E 树上倍增lca

2016-08-01 19:04:46

#### Codeforces Round #476 (Div. 2) [Thanks, Telegram!] E. Short Code CF965E

2018-04-27 12:52:38

#### Codeforces Round #364 (Div. 2)(A,B,C,D) 题解

2016-07-23 10:51:56

#### Codeforces Round #479 (Div. 3) F. Consecutive Subsequence(思路，最长连续递增子序列)

2018-05-07 09:36:01

#### Codeforces Round #490 (Div. 3) （A，B，C，D，E，F）

2018-06-25 19:55:10

#### Codeforces Round #480 (Div. 2): D. Perfect Groups（思维题）

2018-05-09 17:29:44

#### Codeforces Round #444 (Div. 2)-贪心&尺取-Ratings and Reality Shows

2017-11-11 20:11:11

#### Educational Codeforces Round 36 (Rated for Div. 2) 题解

2018-01-13 23:16:24