Codeforces Round #266 (Div. 2)-C,D
直接暴力从前往后寻找。假设找到1/3sum的位置,那么标记++。找到2/3的位置,总数加上标记数。
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define maxn 550000
#define mod 10000007
#define LL __int64
LL a[maxn];
int main()
{
int n;
while(~scanf("%d",&n))
{
LL sum=0;
for(int i=1;i<=n;i++)
{
scanf("%I64d",&a[i]);
sum+=a[i];
}
if(sum%3)
{
cout<<"0"<<endl;
continue;
}
sum=sum/3;
LL ans=0;
LL now=0;
LL s=0;
for(int i=1;i<n;i++)
{
now+=a[i];
if(sum*2==now)
{
ans+=s;
}
if(now==sum)
{
s++;
}
}
cout<<ans<<endl;
}
return 0;
}
先把a数组变成须要加多少变成h。
然后在对a数组前向差分得出b数组。
cnt:标记到当前位置,有几个l没有和r匹配
假设b[i]==1:
说明当前位置有一个l,cnt++;
假设b[i]==0:
1,当前位置什么都没有
2,当前位置有一个l,一个r。
由于有一个l,所以cnt++.
有一个r。所以总数*=cnt,cnt--;
相当于总数*=(cnt+1);
假设b[i]==-1:
当前位置有一个r,所以总数*=cnt,cnt--;
假设b[i]不等于上面的三种情况,说明无解!
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define maxn 550000
#define mod 1000000007
#define LL __int64
LL a[maxn];
LL b[maxn];
int main()
{
int n,h;
while(~scanf("%d%d",&n,&h))
{
for(int i=1;i<=n;i++)scanf("%I64d",&a[i]);
for(int i=1;i<=n;i++)a[i]=h-a[i];
for(int i=1;i<=n+1;i++)
{
b[i]=a[i]-a[i-1];
}
LL ans=1;
LL cnt=0;
for(int i=1;i<=n+1;i++)
{
if(b[i]==1)
{
cnt++;
}
else if(b[i]==-1)
{
ans=ans*(cnt)%mod;
cnt--;
}
else if(b[i]==0)
{
ans=ans*(cnt+1)%mod;
}
else
{
ans=0;break;
}
ans=ans%mod;
}
cout<<ans<<endl;
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
Codeforces Round #266 (Div. 2)-C,D的更多相关文章
- Codeforces Round #266 (Div. 2)
http://codeforces.com/contest/466 噗,b没写出来啊.a写完后过了40分钟了啊,罚时4次啊!果然太弱 总结: a题看错题,没有考虑m>=n其实也是可行的,导致调了 ...
- Codeforces Round #266 (Div.2) B Wonder Room --枚举
题意:给出一个两边长为a,b的矩形,要求增加a和增加b使a*b>=6*n且a*b最小. 解法:设新的a,b为a1,b1,且设a<b,那么a<=a1<=ceil(sqrt(6*n ...
- Codeforces Round #266 (Div. 2) D
D. Increase Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #266 (Div. 2)B(暴力枚举)
很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实. 两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质. 这道题找 ...
- Codeforces Round #266 (Div. 2) C. Number of Ways
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split ...
- 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连试试水的深浅..... ...
随机推荐
- cer, pfx 创建,而且读取公钥/密钥,加解密 (C#程序实现)
PKI技术(public key infrastructure)里面,cer文件和pfx文件是非经常见的.通常cer文件中面保存着公钥以及用户的一些信息,pfx里面则含有私钥和公钥. 用makecer ...
- Hive自己定义函数的使用——useragent解析
想要从日志数据中分析一下操作系统.浏览器.版本号使用情况.可是hive中的函数不能直接解析useragent,于是能够写一个UDF来解析.useragent用于表示用户的当前操作系统,浏览器版本号信息 ...
- ShareSDK for Android 2.3.8它已发表
ShareSDK for Android 2.3.8已经公布,本次更新内容包含: 1.一键分享加入"摇一摇截图分享"功能 3.优化一键分享截图分享功能 4.一键分享编辑页界面微调 ...
- 乐在其中设计模式(C#) - 代理模式(Proxy Pattern)
原文:乐在其中设计模式(C#) - 代理模式(Proxy Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 代理模式(Proxy Pattern) 作者:webabcd 介绍 为 ...
- jQuery插件主要有两种扩展方式
jQuery插件主要有两种扩展方式: 扩展全局函数方式. 扩展对象方法方式. 扩展全局函数方式 扩展全局函数方式定义的插件,即类级别插件,可以通过jQuery.extend()来进行定义.定义格式为: ...
- UVa 572 Oil Deposits(DFS)
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil ...
- 创建Oracle的用户 create user scott identified by tiger;
在命令行里sqlplus 以system身份登录,password是自己设的system C:\Users\Administrator>sqlplus SQL*Plus: Release 10. ...
- jq实现图像旋转木马:轮焦点+关于控制+自己主动旋转木马
资源:http://www.ido321.com/862.html html代码: 1: <!DOCTYPE html> 2: <html lang="en"&g ...
- c# 判断字符是否是全角, 获取字符串的字节数 , 获取字符串指定长度字节数的字符串
1 Encoding.Default.GetByteCount(checkString); =2 全角 =1 半角 /// <summary> /// 获取字符串的字节长度 /// &l ...
- 嵌入在网页上Flash媒体播放器(1)
做的项目,在不久的将来相关的Flash玩家使用,需要播放视频的网页上,不同的视频资源,需要不同的球员.基于使用稳定性.的嵌入式和嵌入式复杂性能的优点概括起来有两种方式(不同的玩家),视频资源也略有不同 ...