C - Number of Ways

直接暴力从前往后寻找。假设找到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;
}

D - Increase Sequence

先把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的更多相关文章

  1. Codeforces Round #266 (Div. 2)

    http://codeforces.com/contest/466 噗,b没写出来啊.a写完后过了40分钟了啊,罚时4次啊!果然太弱 总结: a题看错题,没有考虑m>=n其实也是可行的,导致调了 ...

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

  3. Codeforces Round #266 (Div. 2) D

    D. Increase Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #266 (Div. 2)B(暴力枚举)

    很简单的暴力枚举,却卡了我那么长时间,可见我的基本功不够扎实. 两个数相乘等于一个数6*n,那么我枚举其中一个乘数就行了,而且枚举到sqrt(6*n)就行了,这个是暴力法解题中很常用的性质. 这道题找 ...

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

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

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

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

  8. Codeforces Round #368 (Div. 2)

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

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

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

随机推荐

  1. simpleDateFormat日期格式转换

    1------------------------------------------------------------------------------------- package com.n ...

  2. [原创] linux deepin 2014.1下编译putty

    在网上找了很久,都没有找到linux下直接可以用的putty程序,最终在putty官网找到了源代码 点击下载 把源代码下载回来. 1.下载源代码 2.安装依赖库 如果系统中没有安装过libgtk2.0 ...

  3. 玩转html5(四)----使用canvas画一个时钟(可以动的哦!)

    先给个效果图,我画的比较丑,大家可以自己美化一下, 直接上代码: <!DOCTYPE html> <meta charset="utf-8"> <ht ...

  4. Recall(检出率)和 Precision(准确性)

    这两个方面是模式识别和信息检索使用措施值. 浅显易懂的理解,用以下的图片和公式最好只是. 那么 - 召回率R:用检索到相关文档数作为分子.全部相关文档总数作为分母.即R = A / ( A + C ) ...

  5. 在WPF中处理Windows消息

    在Winform中 处理Windows消息通过重写WndProc方法 在WPF中 使用的是System.Windows. Sytem.Windows.Controls等名字空间,没有WndProc函数 ...

  6. SQL 修改排序规则的问题 sql_latin1_general_cp1_ci_as

    在一个项目中遇到:用原来的数据库生成的脚本,然后部署到新的服务器上,数据库的SQL_Latin1_General_CP1_CI_AS 怎么查询出来汉字都是乱码了. 遂查解决方法. 需要执行这个 ALT ...

  7. new TimerTask(robot)(转)

    import java.awt.Dimension; import java.awt.Robot; import java.awt.Toolkit; import java.io.PrintStrea ...

  8. cygwin,在win中开发linux程序

    cygwin,在win中开发linux程序 http://www.cygwin.cn/site/info/show.php?IID=1001  很多用windows的朋友不习惯于用linux的开发环境 ...

  9. java设计模式演示示例

    创建一个模式 1.工厂方法模式(Factory Method)  该程序创建的操作对象,独自一人走出流程,创建产品工厂接口.实际的工作转移到详细的子类.大大提高了系统扩展的柔性,接口的抽象化处理给相互 ...

  10. jwt (JSON Web Token)官方说明

    http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-32#appendix-A 相关文章 http://haomou.net/2014 ...