Codeforces Round #193 (Div. 2)
题目地址: http://codeforces.com/contest/332
第一题:题目又臭又长,读了好长时间才读懂。
n个人,你是0号,从0开始到n-1循环做动作,只要你前面三个人动作一样,你就喝一杯橙汁,问你能喝多少杯,
模拟
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; typedef __int64 LL;
const int N=20005;
const LL II=1000000007;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0); char s[N]; int main()
{
int i,j,n;
while(cin>>n)
{
scanf("%s",s);
int len=strlen(s),sum=0;
for(i=0;i<len;)
{
if((i+n)<len)
{
i=i+n;
if(s[i-1]==s[i-2]&&s[i-2]==s[i-3])
{
sum++;
}
}
else
break;
}
cout<<sum<<endl;
}
return 0;
}
第二题:给你n个数,要你求一个k使得[a; a + k - 1] 与[b; b + k - 1]的和最大,保证这两个集合不想交。
1、相当于两个dp吧
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; typedef __int64 LL;
const int N=200005;
const LL II=1000000007;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0); LL x[N];
LL dp[N]; int main()
{
LL i,j,n,k;
while(scanf("%I64d%I64d",&n,&k)!=EOF)
{
for(i=1;i<=n;i++)
scanf("%I64d",&x[i]);
memset(dp,0,sizeof(dp));
for(i=1;i<=k;i++)
dp[1]+=x[i];
for(i=2;i<=n-k+1;i++)
dp[i]=dp[i-1]-x[i-1]+x[i+k-1];
LL max1=dp[1],Max=0;
int t1,t2,te=1;
for(i=1+k;i<=n-k+1;i++)
{
if((dp[i]+max1)>Max)
{
Max=dp[i]+max1;
t1=te; t2=i;
}
if(max1<dp[i-k+1])
{
max1=dp[i-k+1];
te=i-k+1;
}
}
printf("%d %d\n",t1,t2);
}
return 0;
}
2、RMQ算法
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <iterator>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cctype>
using namespace std; typedef __int64 LL;
const int N=200005;
const LL II=1000000007;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0); LL x[N];
LL dp[N];
LL d[N][20]; LL RMQ(int l,int r)
{
int k=0;
while((1<<(k+1))<=(r-l+1))
k++;
return max(d[l][k],d[r-(1<<k)+1][k]);
} int main()
{
int i,j,n,k;
while(scanf("%d%d",&n,&k)!=EOF)
{
for(i=0;i<n;i++)
scanf("%I64d",&x[i]);
memset(dp,0,sizeof(dp));
for(i=0;i<k;i++)
dp[0]+=x[i];
int p=n-k+1;
for(i=1;i<p;i++)
dp[i]=dp[i-1]-x[i-1]+x[i+k-1];
for(i=0;i<p;i++)
d[i][0]=dp[i];
for(j=1;(1<<j)<=p;j++)
for(i=0;i+(1<<j)-1<p;i++)
d[i][j]=max(d[i][j-1],d[i+(1<<(j-1))][j-1]);
LL Max=0,tmp,kk;
int t1,t2;
for(i=0;i<p;i++)
{
if((i+k)<p)
{
LL s=dp[i]+(tmp=RMQ(i+k,p-1));
if(Max<s)
{
Max=s; kk=tmp;
t1=i; t2=i+k;
} }
}
for(j=t2;j<p;j++)
if(dp[j]==kk)
{
t2=j;break;
}
printf("%d %d\n",t1+1,t2+1);
}
return 0;
}
Codeforces Round #193 (Div. 2)的更多相关文章
- Codeforces Round #193 (Div. 2) 部分题解
A:直接判断前三项是否相等 int main() { //FIN; //CHEAT; int n; cin>>n; getchar(); ]; gets(a); int len = str ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- Set Matrix Zeroes -- LeetCode
原题链接: http://oj.leetcode.com/problems/set-matrix-zeroes/ 这是一个矩阵操作的题目,目标非常明白,就是假设矩阵假设有元素为0,就把相应的行和列上面 ...
- mysql监控、性能调优及三范式理解
原文:mysql监控.性能调优及三范式理解 1监控 工具:sp on mysql sp系列可监控各种数据库 2调优 2.1 DB层操作与调优 2.1.1.开启慢查询 在My.cnf文件中添加如 ...
- 74LS183 加法器 【数字电路】
74LS183 搭的一个还有点意思的加法电路,串行进位的 2+6 == 8 大家都懂的哈哈
- Dojo仪表板
Dojo它提供了一个良好的仪表板显示器,的影响,如以下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvR0lTU2hpWGlTaGVuZw==/font/ ...
- NHibernate系列
NHibernate系列 写在前面 这篇总结本来是昨天要写的,可昨天大学班长来视察工作,多喝了点,回来就倒头就睡了,也就把这篇总结的文章拖到了今天. nhibernate系列从开始着手写,到现在前后耗 ...
- Java集合之LinkedHashSet源码分析
1.简介 我们知道Set不允许包含相同的元素,如果试图把两个相同元素加入同一个集合中,add方法返回false.根据源码实现中的注释我们可以知道LinkedHashSet是具有可预知迭代顺序的Set接 ...
- QtNetwork说明(两)使用QT实现360的ctrl+ctrl特征
头文字说明: <span style="font-size:18px;">#ifndef GOOGLESUGGEST_H #define GOOGLESUGGEST_H ...
- SVG 学习(二)--- 创建组合交互式应用
接着上一节的内容,本次学习主要介绍SVG组合式应用以及js交互式应用! 1.组合式应用 绘制两棵带有投影效果的树! <svg width="400" height=" ...
- Azure China
Azure China Azure China (2) Azure China管理界面初探 摘要: <Windows Azure Platform 系列文章目录> 首先是Q&A ...
- 青铜器RDM全面支持CMMI、GJB5000A L2~L5认证评估
青铜器RDM全面实现对CMMI L4.GJB5000A L4的100%支持,并且已经成为众多组织CMMI.GJB5000A落地执行的有效手段,避免认证与执行2张皮,有利于体系的贯彻执行,以下是青铜器R ...