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连试试水的深浅..... ...
随机推荐
- 【原创】leetCodeOj ---Convert Sorted List to Binary Search Tree 解题报告
原题地址: https://oj.leetcode.com/problems/convert-sorted-list-to-binary-search-tree/ 题目内容: Given a sing ...
- 採訪The Molasses Flood:BioShock Infinite 游戏之后又一大作
Xsolla有幸与Flame in the Flood游戏的开发人员之中的一个-----Forrest Dowling进行了採訪,Flame in the Flood这款非常棒的游戏在Kickstar ...
- C++习题 对象数组求最大值
Description 建立一个对象数组,内放n(<10)个学生的数据(学号.成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出n个学生中成绩最高者,并输出其学号. In ...
- 玩转Web之easyui(一)-----easy ui datagird 分页
easy ui 中数据表格的分页其实是很简单的,分页是在数据表格可以正常显示数据的基础上进行的,在这里给出servlet的代码,其中selectAll()方法是从数据库中提取所有数据, 分页的一种思路 ...
- 注意事项: Solr设备 Hello World
试用 Solr-4.10.2 一 shards, 这两款机器 一是垃圾 rm -r example/solr/collection1/data/* 启动一个 node cd example java ...
- 《Linux Device Drivers》第十六章 块设备驱动程序——note
基本介绍 块设备驱动程序通过主传动固定大小数据的随机访问设备 Linux核心Visual块设备作为基本设备和不同的字符设备类型 Linux块设备驱动程序接口,使块设备最大限度地发挥其效用.一个问题 一 ...
- React-Native入门
React-Native入门指导之iOS篇 React-Native 入门指导系列教程目录 一.准备工作 (已完成) 二.项目介绍与调试 三.CSS样式与Flex布局 四.常用UI控件的使用 五.JS ...
- BZOJ3362 [Usaco2004 Feb]Navigation Nightmare 导航噩梦
标题效果:自脑补. 思维:与维护两个维度和可设置为检查右. 注意,标题给予一堆关系的.我们应该加入两对关系. Code: #include <cstdio> #include <cs ...
- 利用hibernate的session查询数据库,而且在jsp页面显示表内容的方法
试过了非常多种方法都没有成功,最终让我找到了这样的方法! 首先在后台写代码: Transaction tx = session.beginTransaction(); List list = sess ...
- Java经典23结构模型的设计模式(三)------附加代理模式、适配器型号、Facade模式的差异
本文介绍了7样的结构模型中的其余2种:轻量级.代理模式. 一.享元模式FlyWeight 享元模式比較简单且重要,在非常多场合都被用到.仅仅只是封装起来了用户看不到.其概念:运用共享内存技术最大限度的 ...