[思路题 乱搞] BZOJ 4377 [POI2015]Kurs szybkiego czytania
2016-03-20 19:34
417 查看
%%% Claris :/article/6707048.html
每个ai是互不相同的
所以在以ai为下标的一个表删一些区间,剩余的就是解
每个ai是互不相同的
所以在以ai为下标的一个表删一些区间,剩余的就是解
#include<cstdio> #include<cstdlib> #include<algorithm> using namespace std; inline char nc() { static char buf[100000],*p1=buf,*p2=buf; if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; } return *p1++; } inline void read(int &x) { char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b; } inline void read(char *s) { char c=nc(); int len=0; for (;!(c=='0' || c=='1');c=nc()); for (;c=='0' || c=='1';s[++len]=c,c=nc()); s[++len]=0; } struct edge{ int x,y; edge(int x=0,int y=0):x(x),y(y) {} bool operator < (const edge &B) const{ return x<B.x; } }E[4000005]; int cnt; int n,m,A,B,P; char w[1000005]; inline void add(int a,int b,int c,int d){ if(a) E[++cnt]=edge(0,a); if(b<c) E[++cnt]=edge(b,c); if(d<n) E[++cnt]=edge(d,n); } int main() { freopen("t.in","r",stdin); freopen("t.out","w",stdout); read(n); read(A); read(B); read(P); read(m); read(w); for (int i=1;i<=m;i++,(B+=A)%=n) if (w[i]=='0') add(0,max(P-B,0),n-B,min(P-B+n,n)); else add(max(P-B,0),n-B,min(P-B+n,n),n); B=n-A; for(int i=n-1;i>n-m;B=(B-A+n)%n,i--) E[++cnt]=edge(B,B+1); E[++cnt]=edge(n,n+1); sort(E+1,E+cnt+1); int ans=0,r=0; for (int i=1;i<=cnt;i++) { if(E[i].x>r) ans+=E[i].x-r; if(E[i].y>r) r=E[i].y; } printf("%d\n",ans); return 0; }
相关文章推荐
- Django:介绍Django
- Some essential tips for algorithm design(一些重要的算法设计技术)
- 【Heaven Cow与God Bull】题解
- hdu 4722 Good Numbers(规律题)
- GO语言入门到精通(一)Golang环境搭建
- 【GOF23设计模式】--工厂模式
- go语言cgo -- C与Go互调
- 高仿GooglePlay(一)
- 【GOF23设计模式】--单例模式
- __init__() got an unexpected keyword argument 'context processor'解决方法
- goldsystem
- Django rest framework 常用外键命令 (加入、删除、查看所有、查看除了自己以外的所有、摘除分离对象间外键关系)
- Category(类别)和扩展(Extension)的区别
- 后缀树系列一:概念以及实现原理( the Ukkonen algorithm)
- GO1.6语言学习笔记3-工具篇(SublimeText 3+GoSublime组合)
- 编写GO的WEB开发框架 (十四): daemon和greaceful
- Mongoose 学习
- LightOJ1030 Discovering Gold(概率DP)
- CF 653E(Bear and Forgotten Tree 2-链表优化搜索)
- GDCPC GO