A Sereja and Algorithm

题意:给定有x,y,z组成的字符串,每次询问某一段s[l, r]能否变成变成zyxzyx的循环体。

分析:

分析每一段x,y,z数目是否满足构成循环体,当然长度<3的要特判。

代码:

 #include <bits/stdc++.h>
#define in freopen("solve_in.txt", "r", stdin);
#define pb push_back using namespace std;
typedef long long LL; const int maxn = (int)1e5 + ;
char s[maxn];
int cnt[maxn][];
int main() { int m;
scanf("%s", s+);
scanf("%d", &m);
int len = strlen(s+);
for(int i = ; i <= len; i++) {
for(int k = ; k < ; k++)
cnt[i][k] = cnt[i-][k];
cnt[i][s[i]-'x']++;
}
for(int i = ; i < m; i++) {
int l, r;
scanf("%d%d", &l, &r);
int a = cnt[r][]-cnt[l-][];
int b = cnt[r][]-cnt[l-][];
int c = cnt[r][]-cnt[l-][];
int tmp = r-l+;
if(tmp < )
puts("YES");
else { if(tmp% == ) {
if(a == b && b == c)
puts("YES");
else puts("NO");
} else if(tmp% == ) {
if((a == b && c - b == ) || (b == c && a-b == ) || (a == c &&b -a == ))
puts("YES");
else puts("NO");
} else {
if((a == b && a-c == ) || (b == c && b-a==) || (a == c && a-b == ))
puts("YES");
else puts("NO");
}
}
}
return ;
}

B Sereja ans Anagrams

题意:给定2个数组,a[1...n],以及b[1...m]问能否从a中等间隔的选取m个数,使得这m个数与b中各个整数数目对应相等。

分析:

容易知道由于是等间隔p的出现,所以可以将a[1..n]的数按间隔分成p组,每次添加一个数时,看相应的组m个数形成的序列是否和b中数的数目对应相等,每次添加,减少一个数,最多改变2个数的数目,看是不是所有的数的数目都满足与在b中的相等。感觉和单调队列类似。

代码:

 #include <bits/stdc++.h>
#define in freopen("solve_in.txt", "r", stdin);
#define pb push_back using namespace std;
typedef long long LL;
typedef map<int, int> MPII; const int maxn = *(int)1e5;
int n, m, p;
MPII mps, mx[maxn];
vector<int> ans;
int a[maxn], b[maxn];
int sat[maxn];
queue<int> q[maxn]; int main() { scanf("%d%d%d", &n, &m, &p);
for(int i = ; i < n; i++) {
scanf("%d", a+i);
}
int dif = ;
for(int i = ; i < m; i++) {
int t;
scanf("%d", &t);
if(mps[t] == )
dif++;
mps[t]++;
}
for(int i = ; i < n; i++) {
int di = i%p;
if(q[di].size() >= m) {
int u = q[di].front();
q[di].pop();
if(mx[di][u] == mps[u])
sat[di]--;
else if(mx[di][u] == mps[u]+)
sat[di]++;
mx[di][u]--;
}
int u = a[i];
q[di].push(a[i]);
if(mx[di][u] == mps[u])
sat[di]--;
else if(mx[di][u] == mps[u]-)
sat[di]++;
mx[di][u]++;
if(sat[di] == dif)
ans.pb(i-(m-)*p);
}
cout<<ans.size()<<endl;
for(int i = ; i < ans.size(); i++) {
printf("%d%c", ans[i]+, i == ans.size()-?'\n':' ');
}
return ;
}

C Sereja and the Arrangement of Numbers

题意:n个位置,从m不同的数中选一些数去填充,构成一个数组,数组中出现的任何两个数一定要在数组中至少连续出现一次,每个数都有一个代价,要求选出的数总代价最大!

分析:首先肯定的是选出代价尽量大的数,那么就要确定n个位置最多放多少个不同的数,做的时候其实是想到了完全图的,但是没继续想下去。由于任何两个数都要相邻出现,所以肯定是满足完全图关系的,但是如果将相邻关系看做一条边的话,n个位置n-1条边,而且这n-1条边是能够从左走到右,也就是构成一个半欧拉图。

半欧拉图:最多有两个点度数为奇数。对于偶数个节点完全图,每个点度数为奇数,添加一条边能够使得两个点度数变为偶数,所以最少需要添加(点数/2-1)条边构成半欧拉图,因为最终还是允许两个点度数为奇数。奇数个结点完全图,度数为偶数,所以不需要添加边了。

这样根据,图中n-1条边二分最多能放置的结点数,得到数组中最多出现多少个不同的数,贪心选取最大就行了。

代码:

 #include <bits/stdc++.h>
#define in freopen("solve_in.txt", "r", stdin);
#define pb push_back using namespace std;
typedef long long LL;
typedef map<int, int> MPII;
const int maxn = (int)1e5 + ; int w[maxn];
int getAns(int lim, int r){
int l = ;
while(l < r){
int mid((l+r+)>>);
int tmp;
if(mid&){
tmp = ((LL)mid*(mid-)>>);
if(tmp <= lim)
l = mid;
else r = mid-;
}
else {
tmp = ((LL)mid*(mid-)/+mid/-);
if(tmp <= lim)
l = mid;
else r = mid-;
}
}
return l;
}
int main(){ int n, m;
scanf("%d%d", &n, &m);
for(int i(); i != m; i++){
scanf("%*d%d", w+i);
}
sort(w, w+m, greater<int> ());
n = getAns(n-, m);
LL ans = ;
for(int i = ; i != n; i++)
ans += w[i];
cout<<ans<<endl;
return ;
}

Codeforces Round #215 (Div. 1)的更多相关文章

  1. Codeforces Round #215 (Div. 2) B. Sereja and Suffixes map

    B. Sereja and Suffixes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  2. Codeforces Round #215 (Div. 1) B. Sereja ans Anagrams 匹配

    B. Sereja ans Anagrams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...

  3. Codeforces Round #215 (Div. 2) D. Sereja ans Anagrams

    http://codeforces.com/contest/368/problem/D 题意:有a.b两个数组,a数组有n个数,b数组有m个数,现在给出一个p,要你找出所有的位置q,使得位置q  q+ ...

  4. Codeforces Round #215 (Div. 2) C. Sereja and Algorithm

    #include <iostream> #include <vector> #include <algorithm> #include <string> ...

  5. Codeforces Round #215 (Div. 2) B. Sereja and Suffixes

    #include <iostream> #include <vector> #include <algorithm> #include <set> us ...

  6. Codeforces Round #215 (Div. 2) A. Sereja and Coat Rack

    #include <iostream> #include <vector> #include <algorithm> using namespace std; in ...

  7. Codeforces Round #215 (Div. 1) B

    出来冒个泡 由于数比较大  开了map计数  然后边走边删边加 勉强可过 #include <iostream> #include<cstdio> #include<cs ...

  8. Codeforces Round #215 (Div. 2) D题(离散化+hash)

    D. Sereja ans Anagrams time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. JDK Tools - xjc: 将 XML Schema 编译成 Java 类

    xjc 是 JAXB 将 xsd 生成 Java 类的工具. 命令格式 xjc [ options ] schema file/URL/dir/jar ... [-b bindinfo ] ... 命 ...

  2. gluster 安装配置基本指南

    基于网络上的多篇文章,做了一些调整. gluster安装 ###  Installing Gluster wget -P /etc/yum.repos.d http://download.gluste ...

  3. android NDK 笔记

    *************************************************华丽的分割线********************************************* ...

  4. 牛客OJ——[编程题]A+B和C__如何输入多组测试数据(测试OK)

    几个要注意的地方: (1)Java OJ,必须将类名写成Main (2)关于如何输入多组测试数据,用二维数组去存储是一个方法,直接在while里面做也可以          但是如果  (3)关于整形 ...

  5. C# IO操作(四)大文件拷贝(文件流的使用)、文件编码

         大文件拷贝(文件流的使用).文件编码 首先说一下大文件拷贝和文件流,因为计算机的内存资源是有限的,面对几个G甚至更大的文件,需要通过程序来完成拷贝,就需要用到文件流(因为我们无法做到把文件一 ...

  6. 安装oracle 12c遇到问题

    安装前步骤:更改用户账户控制设置:从不通知  出现 "SEVERE: [FATAL] [INS-30014] 无法检查指定的位置是否位于 CFS 上" 解决办法:重新设置hosts ...

  7. 12天学好C语言——记录我的C语言学习之路(Day 2)

    12天学好C语言--记录我的C语言学习之路 Day 2: 我建议大家每一天学习之前都仅凭记忆去敲前一天敲过的最后一个程序,或者敲前一天你认为最难最长的一个程序,如果一晚上的睡眠之后不看书还能敲的出来, ...

  8. Python爬虫第一集

    import urllib2 response = urllib2.urlopen("http://www.baidu.com") print response.read() 简单 ...

  9. Headfirst设计模式的C++实现——状态模式(State)

    state.h #ifndef _STATE_H_ #define _STATE_H_ class GumballMachine; class State { public: ; ; ; ; Stat ...

  10. DataGridView如何快速导出Excel

    从DataGridView或DataTable导出Excel文件,为了按照数据类型设置单元格格式,导出Excel时速度都比较慢,一直找不到好的办法. 最后从外文网站上找到解决办法,使用ws.get_R ...