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后和给 ...
随机推荐
- ZOJ 2675 Little Mammoth(计算几何)
圆形与矩形截面的面积 三角仍然可以做到这一点 代码: #include<stdio.h> #include<string.h> #include<stdlib.h> ...
- js前端分页之jQuery
锋利的js前端分页之jQuery 大家在作分页时,多数是在后台返回一个导航条的html字符串,其实在前端用js也很好实现. 调用pager方法,输入参数,会返回一个导航条的html字符串.方法的内部比 ...
- 移动应用跨平台框架江湖将现终结者?速来参拜来自Facebook的React Native
React Native使用初探 February 06 2015 Facebook让所有React Conf的参与人员都可以初尝React Native的源码---一个编写原生移动应用的方法.该方法 ...
- Ninject.Extensions.
最近在使用IoC进行一个较复杂的项目进行架构,在IoC的选择上让我很是纠结.首先我不喜欢大量的配置文件进行配置,那简直是噩梦,比学习一门编程语言还痛苦.我喜欢前一段时间看EF的CodeFirst的那种 ...
- .Net IOC 之Unity
.Net IOC 之Unity 在码农的世界里,为了应付时常变更的客户需求,增加的架构的客扩展性,减少工作量.IOC诞生了,它是一种可以实现依赖注入和控制对象生命周期的容器.最为一个有节操.有追求的码 ...
- Linux环境下搭建php开发环境的操作步骤
本文主要记载了通过编译方式进行软件/开发环境的安装过程,其他安装方式忽略! 文章背景: 因为php和Apache等采用编译安装方式进行安装,然而编译安装方式,需要c,c++编译环境, 通过apt方式安 ...
- 修改servu数据库密码 servu加密方式
项目要求可以有用户自行修改servu密码.servu可以通过odbc访问access\mysql\sqlserver数据库.我们直接通过创建web来修改就可以了. 不过问题来了,密码是加密的...通过 ...
- ASP.NET MVC IOC之Unity攻略
ASP.NET MVC IOC之Unity攻略 一.你知道IOC与DI吗? 1.IOC(Inversion of Control )——控制反转 即依赖对象不在被依赖模块的类中直接通过new来获取 先 ...
- Orchard Module,Theme,Core扩展加载概述
Orchard 源码探索(Module,Theme,Core扩展加载概述) 参考: http://www.orchardch.com/Blog/20120830071458 1. host.Initi ...
- C#函数式程序设计之泛型
Intellij修改archetype Plugin配置 2014-03-16 09:26 by 破狼, 204 阅读, 0 评论,收藏, 编辑 Maven archetype plugin为我们提供 ...