题目地址: 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使得[aa + k - 1] 与[bb + 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)的更多相关文章

  1. Codeforces Round #193 (Div. 2) 部分题解

    A:直接判断前三项是否相等 int main() { //FIN; //CHEAT; int n; cin>>n; getchar(); ]; gets(a); int len = str ...

  2. 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 ...

  3. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  4. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

随机推荐

  1. jQuery+PHP掷色子抽奖

    原文 jQuery+PHP掷色子抽奖 本文以大富翁游戏为背景,综合运用jQuery和PHP知识,设计出以掷色子点数来达成抽奖的效果,当然抽奖概率是可控的,开发者可以将本实例稍作修改即可运用到网站中的抽 ...

  2. [LeetCode]Copy List with Random Pointer &amp;Clone Graph 复杂链表的复制&amp;图的复制

    /** * Definition for singly-linked list with a random pointer. * struct RandomListNode { * int label ...

  3. 使用.NET REACTOR制作软件许可证

    原文:使用.NET REACTOR制作软件许可证 软件下载地址:http://www.eziriz.com/downloads.htm 做一个简单的许可证系统,下面是具体步骤: 1,  OPEN AS ...

  4. Bundle压缩JS和CSS

    ASP.NET MVC之Bundle压缩JS和CSS 介绍Bundle之前先引用<淘宝技术这十年>中一段话,对Web前端稍微有点常识的人都应该知道,浏览器下一步会加载页面中用到的CSS.J ...

  5. Ajax.ActionLink 用法

    Ajax.ActionLink 用法 Ajax 属性的ActionLink方法可以创建一个具有异步行为的锚标签. ActionLink方法的第一个参数指定了链接文本,第二个参数是要异步调用的操作的名称 ...

  6. Fedora 20中解决zip解压文件时中文文件名的乱码问题[已解决]

    该方法的原文地址: http://wangqige.com/the-solution-of-unzip-files-which-zip-under-windows/(链接已失效) 解决方法:保存如下P ...

  7. Spring IOC之容器扩展点

    一般来说,一个应用开发者不需要继承ApplicationContext实现类.取而代之的是,Spring IoC容器可以通过插入特殊的整合接口的实现来进行扩展.下面的几点将要讲述这些整合的接口. 1. ...

  8. 使用SQL Server 2005数据库管理工具 - 初学者系列 - 学习者系列文章

    本文讲述使用SQL Server 2005 Express数据库管理工具的使用. 1.打开数据库管理工具 2.选择下面的SQL Server 身份验证,因为在安装数据库的时候设置了sa的密码. 3.选 ...

  9. IOS开发苹果官方Sample Code及下载地址

    IOS开发苹果官方Sample Code及下载地址 在线浏览地址:https://developer.apple.com/library/ios/navigation/#section=Resourc ...

  10. SSIS中Sql Task 获取系统变量

    原文:SSIS中Sql Task 获取系统变量 执行 SQL 任务使用不同的连接类型时,SQL 命令的语法使用不同的参数标记.例如,ADO.NET 连接管理器类型要求 SQL 命令使用格式为 @var ...