Codeforces Round #266 (Div. 2)-C,D
2015-10-28 09:11
288 查看
C - Number of Ways
直接暴力从前往后寻找。假设找到1/3sum的位置,那么标记++。找到2/3的位置,总数加上标记数。
先把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]不等于上面的三种情况,说明无解!
直接暴力从前往后寻找。假设找到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; }
相关文章推荐
- jquery倒计时实现
- http的post传送文件原理
- ashx一般处理程序和HttpHandler
- Objective-C学习准备__C语言7
- 1分钟学会用java发送邮件
- Java 获取客户端真实ip地址,规则及验证
- Java7/Java8中HashMap解析
- Oracle 树操作(select…start with…connect by…prior)
- 线程池的作用
- python----slots属性安全类
- python批量执行 map reduce
- 全面理解Unity加载和内存管理机制之二:进一步深入和细节
- JS 浏览器兼容性问题汇总
- ASP.NET Web API接受AngualrJS的QueryString的两种方式
- 线性表(一)——顺序表(1)
- error C2027: useof undefined type 'A' see declaration of 'A'
- java中文件复制
- swift-辞典NSDictionary定义,变化的关键,删/加入关键
- 你真的会玩SQL吗?之逻辑查询处理阶段
- 自定义标签&&JSTL标签库详解