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. ORM中去除反射,添加Expression

    之前接触了别人的ORM框架,感觉牛掰到不行,然后试着自己来写自己的ORM. 最初从园子里找到其他人写的反射的例子: List<PropertyInfo> pis = typeof(T).G ...

  2. asp.net_MVC_jq三级联动

    数据库结构 建立三张表,Association,Team,Player 关系如下: 建立asp.net MVC 3项目,在HomeController.cs中利用Linq to SQL获取数据 首先实 ...

  3. 20160531-20160607springmvc入门

    springmvc的基础知识 什么是springmvc? springmvc框架原理(掌握) 前端控制器.处理器映射器.处理器适配器.视图解析器 springmvc入门程序 目的:对前端控制器.处理器 ...

  4. Windows Server 2008 R2安装IIS

    在"服务器管理器"中选择"添加角色".   在"服务器角色"步骤选择"Web 服务器(IIS)".   "角色 ...

  5. C#+ArcEngine 序列化和反序列化AE对象

    http://www.cnblogs.com/jindin/archive/2009/07/23/1529695.html 在AE开发过程,总是要将某些对象暂时存储起来,像element,layer, ...

  6. C# 打印多页tif

    注意点: 1.计算image对象总页数 image.GetFrameCount(FrameDimension.Page); 2.初始化当前页,并获取指定页内容 image.SelectActiveFr ...

  7. iOS启动图片适配问题

    Portrait 是竖屏 top home button Landscape是横屏 left home button retina 要求640x1136pixels, 在右边的Image属性 Expe ...

  8. 18_高级映射:一对一查询(使用resultMap)

    [简述] 数据库模型和数据等信息与上一篇博文相同. 需求也同上一篇博文. [工程截图] [User.java]POJO package cn.higgin.mybatis.po; import jav ...

  9. NSDate与 NSString 、long long类型的相互转化

    我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3560280.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...

  10. VS2010 EntityFramework Database First

    本文演练介绍如何使用实体框架进行 Database First 开发.通过 Database First,可以从现有数据库对模型进行反向工程处理.模型存储在一个 EDMX 文件(扩展名为 .edmx) ...