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. ACM——五位以内的对称素数

    http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1026 五位以内的对称素数 时间限制(普 ...

  2. 重大发现Android studio 如何简单快速修改package name

    好多人都发现Android studio修改包名比较麻烦,只能一级一级的修改,今天偶尔发现了一个快捷方法. 废话不多说: 1 打开项目的AndroidManifest.xml文件 2 鼠标光笔定位到你 ...

  3. [转]第一章 Windows Shell是什么 【来源:http://blog.csdn.net/wangqiulin123456/article/details/7987862】

    一个操作系统外壳的不错的定义是它是一个系统提供的用户界面,它允许用户执行公共的任务,如访问文件系统,导出执行程序,改变系统设置等.MS-DOS有一个Command.COM扮演着这个角色.然而Windo ...

  4. ASP.NET在IIS7中如何更改网站的.net framework框架版本

    IIS7安装好以后使用了.net 2.0 framework框架,经过折腾发现如下方法可以更改框架版本,从而可以部署使用其他版本框架开发的网站 方法一:建立网站时设置.net框架版本 方法二:对于已经 ...

  5. 启用Win8(中文版/核心版)中被阉割的远程桌面服务端

    Windows 8/8.1 标准版(中文版/核心版)中取消了远程桌面服务端,想通过远程连接到自己的电脑就很麻烦了,第三方远程桌面速度又不理想(如TeamViewer).通过以下方法可让系统恢复远程桌面 ...

  6. 编写delegate(明天补充)

    delegate基本上是一种callback机制,让别的类在

  7. N个数随机相加得出固定值的排列组合

    static double[] iArr = new double[10] { 1,2,3,4,5,6,7,8,9,10 }; static Stack<double> stack = n ...

  8. CentOS7 列出服务和对应端口

    列出服务和他们对应的端口: netstat -tulpn

  9. CentOS下Apache+SVN+LDAP的安装与配置

    上班接近4个月了,在公司做配置管理工程师,主要是在Linux下对公司的源代码以及项目发布进行管理.4个月接触了好多新知识,也对各种工具的集成使用搞得云里来雾里去的,所以打算自己搭建一套环境,进行测试. ...

  10. 51nod1057 N的阶乘

    输入N求N的阶乘的准确值.   Input 输入N(1 <= N <= 10000) Output 输出N的阶乘 Input示例 5 Output示例 120参考博客:blog.csdn. ...