[cogs] 1767 [NOI2014]随机数生成器
2015-06-24 16:02
369 查看
ALG :贪心 + BL ???
首先尽量快地求出AA矩阵,嗯,没错直接求出来 = =
然后从11开始枚举到KK,每次判断这个数能否被选取,这样选取出来的序列一定是字典序最小的
然后卡常数卡内存吧
全剧终
首先尽量快地求出AA矩阵,嗯,没错直接求出来 = =
然后从11开始枚举到KK,每次判断这个数能否被选取,这样选取出来的序列一定是字典序最小的
然后卡常数卡内存吧
全剧终
[code]/****************************************\ * Author : ztx * Title : [cogs] 1767. [NOI2014]随机数生成器 * ALG : 贪心 + BL ??? * CMT : * Time : \****************************************/ #include <cstdio> #define Rep(i,l,r) for(i=(l);i<=(r);i++) #define rep(i,l,r) for(i=(l);i< (r);i++) #define Rev(i,r,l) for(i=(r);i>=(l);i--) #define rev(i,r,l) for(i=(r);i> (l);i--) typedef long long ll ; typedef double lf ; /* char Stream[1048576LL] , *ptr = Stream , Strlen ; #define Getchar() (*ptr++) */ #define Getchar() getchar() int CH , NEG ; template <typename TP>inline void read(TP& ret) { ret = NEG = 0 ; ret = 0 ; while (CH=Getchar() , CH<'!') ; if (CH == '-') NEG = true , CH = Getchar() ; while (ret = ret*10+CH-'0' , CH=Getchar() , CH>'!') ; if (NEG) ret = -ret ; } template <typename TP>inline void readc(TP& ret) { while (ret=Getchar() , ret<'!') ; while (CH=Getchar() , CH>'!') ; } template <typename TP>inline void reads(TP *ret) { ret[0]=0;while (CH=Getchar() , CH<'!') ; while (ret[++ret[0]]=CH,CH=Getchar(),CH>'!') ; ret[ret[0]+1]=0; } #define maxn 5010LL #define maxk 25000010LL int N , M , Q , K ; int left[maxn] , right[maxn] ; int T[maxk] , F[maxk] ; inline void Exchange(int&x,int&y) { if (x!=y) x^=y,y^=x,x^=y; } inline void Cover(int x,int y) { int i ; Rep (i,1,x-1) if (y < right[i]) right[i] = y ; Rep (i,x+1,N) if (y > left[i]) left[i] = y ; } int main() { int i , j , x , y ; ll a , b , c , d ; #define READ #ifdef READ freopen("random_2014.in" ,"r",stdin ) ; freopen("random_2014.out","w",stdout) ; #endif /* read */ read(x) , read(a) , read(b) , read(c) , read(d) ; read(N) , read(M) , read(Q) ; K = N*M ; /* pre */ Rep (i,1,K) T[i] = i ; F[0] = x ; Rep (i,1,K) F[i] = (F[i-1] * (a * F[i-1] + b) + c) % d ; Rep (i,1,K) Exchange(T[i],T[F[i]%i+1]) ; Rep (i,1,Q) { read(a) , read(b) ; Exchange(T[a],T[b]) ; } K = 0 ; Rep (i,1,N) { left[i] = 1 , right[i] = M ; Rep (j,1,M) ++ K , F[T[K]] = K ; } /* go */ j = 0 ; Rep (i,1,K) { y = (F[i] - 1) % M + 1 ; x = (F[i] - y) / M + 1 ; if (y<left[x] || y>right[x]) continue ; printf("%d ", i) ; Cover(x,y) ; if (++j == N+M-1) break ; } puts("") ; #ifdef READ fclose(stdin) ; fclose(stdout) ; #else Getchar() ; Getchar() ; #endif return 0 ; }
相关文章推荐
- Redhat本地yum源配置
- 前端针对SEO优化
- Erlang入门(三)——分布式编程
- spring mvc/ RESTful
- innodb 存储引擎
- Ehcache 整合Spring 使用页面、对象缓存
- 如何快速学习stm32--深圳嵌入式学习!
- 设备驱动程序INF文件的处理过程
- 查看销售订单时,报了一个错误消息,“项目不符合计划行(程序错误)”
- Zabbix监控Memcached PHP-FPM Tomcat Nginx MySQL 网站日志
- 任意正整数的阶乘
- js中jsonArray的封装处理
- HttpHandler和HttpModule理解
- linux内核驱动中_IO, _IOR, _IOW, _IOWR 宏的用法与解析
- 如何开机就启动node.js程序
- Erlang入门(二)—并发编程
- Linux下VNC配置多个桌面和修改密码 不会当系统重启vnc失效
- Web关于图片上传,缩略图及加水印,还有一些常用的方法
- java join用法
- _IO, _IOR, _IOW, _IOWR 宏的用法与解析