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. JAXB - Validate Document before It is Unmarshalled

    Validation A considerable part of the XML Schema language deals with facets, enabling the programmer ...

  2. Service的一些使用

    service服务一般主要是作为后台服务使用的,前台服务一般结合通知一起. service一般主要用作长期后台服务的,而且和Activity结合性不那么紧密, 一般如果需要频繁的更新UI主要是用Act ...

  3. 【转】ASP.NET MVC 使用 FluentScheduler 定时器计划任务

    MacBook Pro 只有四个 USB Type-C 接口是否错了? 一项新技术的诞生总会对已存在的事物造成冲击或影响,如果大家都害怕冲击与影响,那这个世界永远像现在不变就行了,大家都好好的,待在自 ...

  4. WCF编程系列(三)地址与绑定

    WCF编程系列(三)地址与绑定   地址     地址指定了接收消息的位置,WCF中地址以统一资源标识符(URI)的形式指定.URI由通讯协议和位置路径两部分组成,如示例一中的: http://loc ...

  5. CSS高度塌陷

    问题描述:当父元素只包含浮动的元素的时候,且父元素没有设置高度,如果父元素设置了边框border,那么看起来子元素不在父元素之内. 比如这样: html: <div id="paren ...

  6. Java架构必会几大技术点(转)

    关于学习架构,必须会的几点技术: 1. java反射技术 2. xml文件处理 3. properties属性文件处理 4. 线程安全机制 5. annocation注解 6. 设计模式 7. 代理机 ...

  7. ZOJ 2392 The Counting Problem(模拟)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1368 题目大意:计算从S到T中所有的数,其中0,1,2,3,4,5, ...

  8. 关于atoi的实现

    一.关于atoi atol的实现 __BEGIN_NAMESPACE_STD __extern_inline double __NTH (atof (__const char *__nptr)) { ...

  9. GNU glibc

    在线G-lib-c(GNU C Library库)网站 参考: 1.bitsToTypes

  10. 九度OJ 1024 畅通工程 -- 并查集、贪心算法(最小生成树)

    题目地址:http://ac.jobdu.com/problem.php?pid=1024 题目描述:     省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但 ...