ZOJ 刷题记录 小黑屋 (`・д・´)
P1006:模拟
然而我的同余方程能过样例然而就是WA⊙﹏⊙b
【已查明:扩展欧几里得算法出了很隐蔽的问题】
int exGcd(int x,int y,int& a,int& b) //ax+by=gcd(x,y) { ; b=; return x; } int res=exGcd(y,x%y,a,b); int t=a; a=b; b=t-x/y*b; return res; }
Correct exGcd Code
#include <cstdio> #include <cstring> #include <algorithm> inline int code(char x) { switch(x) { ; ; ; } } inline char decode(int x) { switch(x) { : return '_'; : return '.'; ; } } int K; ; ; char cpt[maxL]; bool input() { scanf("%d",&K); if(!K) return false; return scanf("%s",cpt); } int exGcd(int x,int y,int& a,int& b) //ax+by=gcd(x,y) { ; b=; return x; } int res=exGcd(y,x%y,a,b); int t=a; a=b; b=t-b*x/y; return res; } int mdEq(int a,int b,int m) //ax=b(mod m) { //let ax+km=b int x,k; int g=exGcd(a,m,x,k); x*=(b/g); x%=m; ?x+m:x; } void solve() { int l=strlen(cpt); ;j<l;j++) { int i=mdEq(K,j,l); putchar(decode((i+code(cpt[i]))%apb)); } putchar('\n'); } int main() { while(input()) solve(); ; }
Problem:ZOJ P1006 WA
#include <cstdio> #include <cstring> #include <algorithm> ],down[],left[],right[]; ]; ]; int N,Ns; bool input() { scanf("%d",&N); Ns=N*N; if(!N) return false; ;i<=Ns;i++) scanf("%d%d%d%d",up+i,right+i,down+i,left+i); return true; } bool move(int,int); bool dfs(int); inline bool move(int cur,int i) { used[i]=true; fill[cur]=i; )) return true; used[i]=false; return false; } bool dfs(int cur) { ) return true; bool res=false; ; ; ) st|=; ;i<=Ns;i++) if(!used[i]) { ) { res=move(cur,i); if(res) return true; } ) { int& u=fill[cur-N]; if(up[i]==down[u]) { res=move(cur,i); if(res) return true; } } ) { ]; if(left[i]==right[l]) { res=move(cur,i); if(res) return true; } } else { int& u=fill[cur-N]; ]; if(left[i]==right[l] && up[i]==down[u]) { res=move(cur,i); if(res) return true; } } } return false; } int main() { ); freopen("t.in","r",stdin); while(input()) { ++cs; ) printf("\n"); memset(used,,sizeof(used)); printf()?"Possible":"Inpossible"); } ; }
Problem:ZOJ P1008
P2672:DP+Hash优化转移
然而谁**能告诉我为啥会TLE!!( >﹏<。)
#include <cstdio> #include <cstring> #include <algorithm> #include <list> struct Hash { int val; int pos; Hash(int v,int p):val(v),pos(p) {} }; ; ; std::list<Hash> hash[dv+]; typedef std::list<Hash>::iterator Iter; Iter x; int N; int arr[maxN]; short dp[maxN][maxN]; inline void insertHash(int v,int p) { hash[v&dv].push_back(Hash(v,p)); } inline int findHash(int v,int p) { int res=maxN; for(x=hash[v&dv].begin();x!=hash[v&dv].end();++x) if(x->val == v && x->pos > p && x->pos < res) res=x->pos; : res ; } void init() { ;i<=dv;i++) hash[i].clear(); ;i<=N;i++) insertHash(arr[i],i); } bool input() { if(scanf("%d",&N)==EOF) return false; ;i<=N;i++) scanf("%d",arr+i); return true; } void __solve() { init(); ; int s,t; ;i<N;i++) dp[i][N]=; ;j>;j--) ;i;i--) { int f=findHash(arr[j]+arr[i],j); ) dp[i][j]=; ) > ans) { ans=dp[i][j]; s=i; t=j; } } printf("%d\n%d %d ",ans,arr[s],arr[t]); int f; ) { printf("%d ",arr[f]); s=t; t=f; } printf("\n\n"); } void solve() { ) printf(]); ) printf(],arr[]); else __solve(); } #include <ctime> int main() { while(input()) solve(); ; }
Problem:ZOJ P2672 TLE
P3300:迷之WA
#include <cstdio> #include <cstring> #include <algorithm> ]; bool input() { int v; if(scanf("%d",&v)==EOF) return false; memset(cnt,,sizeof(cnt)); ++cnt[v]; ;i<=;i++) { scanf("%d",&v); ++cnt[v]; } return true; } bool dfs(int eye) { bool res=true; ;i<=;i++) if(cnt[i]) { res=false; break; } if(res) return true; ;i<=;i++) ] && cnt[i+]) { --cnt[i]; --cnt[i+]; --cnt[i+]; res|=dfs(eye); if(res) return true; ++cnt[i]; ++cnt[i+]; ++cnt[i+]; } ;i<=;i++) ) { cnt[i]-=; res|=dfs(eye); if(res) return true; cnt[i]+=; } if(!eye) { ;i<=;i++) ) { cnt[i]-=; res|=dfs(eye+); if(res) return true; cnt[i]+=; } } return res; } void solve() { ; ;i<=;i++) { ) ++cnt[i]; else continue; )) { if(ok++) printf(" %d",i); else printf("%d",i); } --cnt[i]; } printf("\n"); } int main() { while(input()) solve(); ; }
Problem:ZOJ P3300 WA
ZOJ 刷题记录 小黑屋 (`・д・´)的更多相关文章
- ZOJ 刷题记录 (。・ω・)ノ゙(Progress:31/50)
[热烈庆祝ZOJ回归] P1002:简单的DFS #include <cstdio> #include <cstring> #include <algorithm> ...
- PE刷题记录
PE刷题记录 PE60 / 20%dif 这道题比较坑爹. 所有可以相连的素数可以构成一张图,建出这张图,在其中找它的大小为5的团.注意上界的估算,大概在1W以内.1W内有1229个素数,处理出这些素 ...
- leetcode刷题记录--js
leetcode刷题记录 两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但 ...
- Leetcode刷题记录(python3)
Leetcode刷题记录(python3) 顺序刷题 1~5 ---1.两数之和 ---2.两数相加 ---3. 无重复字符的最长子串 ---4.寻找两个有序数组的中位数 ---5.最长回文子串 6- ...
- 刷题记录:[HarekazeCTF2019]encode_and_encode
目录 刷题记录:[HarekazeCTF2019]encode_and_encode 一.知识点 JSON转义字符绕过 php伪协议 刷题记录:[HarekazeCTF2019]encode_and_ ...
- 刷题记录:[De1CTF 2019]Giftbox && Comment
目录 刷题记录:[De1CTF 2019]Giftbox && Comment 一.知识点 1.sql注入 && totp 2.RCE 3.源码泄露 4.敏感文件读取 ...
- 刷题记录:[强网杯 2019]Upload
目录 刷题记录:[强网杯 2019]Upload 一.知识点 1.源码泄露 2.php反序列化 刷题记录:[强网杯 2019]Upload 题目复现链接:https://buuoj.cn/challe ...
- 刷题记录:[XNUCA2019Qualifier]EasyPHP
目录 刷题记录:[XNUCA2019Qualifier]EasyPHP 解法一 1.error_log结合log_errors自定义错误日志 2.include_path设置包含路径 3.php_va ...
- 刷题记录:[DDCTF 2019]homebrew event loop
目录 刷题记录:[DDCTF 2019]homebrew event loop 知识点 1.逻辑漏洞 2.flask session解密 总结 刷题记录:[DDCTF 2019]homebrew ev ...
随机推荐
- 2015第45周五IE11实用开发工具摘录及设置IE缓存
UI响应工具的作用 UI响应工具顾名思义就是查看UI响应时间的工具,通过这个工具可以帮助我们确定应用中的哪些组件占用了多少CPU时间,让我们之后可以更有针对性的进行优化,从而最大限度地改善应用性能,同 ...
- tomcat 配置内存相关
今天早上 ,tomcat 网站页面上出现报错问题.最后还是一位同事解决的,这里记录一下. 1.看了一下页面,他说是内存溢出. 首先找到 双击 Tomw.exe 出现如下图 然后需要配置堆栈大小
- HDOJ/HDU 2561 第二小整数(水题~排序~)
Problem Description 求n个整数中倒数第二小的数. 每一个整数都独立看成一个数,比如,有三个数分别是1,1,3,那么,第二小的数就是1. Input 输入包含多组测试数据. 输入的第 ...
- c语言中static的语义
1.static变量: 1).局部 a.静态局部变量在函数内定义,生存期为整个源程序,但作用域与自动变量相同,只能在定义该变量的函数内使用.退出该函数后, 尽管该变量还继续存在,但不能使用它. b.对 ...
- hdu 4278 Faulty Odometer
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4278 #include<cstdio> #include<cstring> # ...
- SonarQube4.4+Jenkins进行代码检查实例之二
SonarQube4.4+Jenkins进行代码检查实例之二 SonarQube4.4+Jenkins进行代码检查实例之二
- zoj 2734 Exchange Cards【dfs+剪枝】
Exchange Cards Time Limit: 2 Seconds Memory Limit: 65536 KB As a basketball fan, Mike is also f ...
- 层层递进Struts1(七)详解DispatchAction
通过前面几篇博客,不知道大家有没有发现这个问题,虽然现在可以灵活控制跳转了,但是Action的数量还是比较多,如何既能保证跳转灵活,还能减少Action的数量?这就是我们这篇博客所说的Dispatch ...
- 原生JavaScript的省市县三级联动
三级联动是我们写表单时必不可少的,比如在写收货地址时,就用到他了,最近在看原生JavaScript,从基础写起,待完善,以后再写个jquery版的. <!DOCTYPE html> < ...
- 【Android - 框架】之Glide的使用
一.Glide简介: Glide是Google官方推荐的一个图片加载和缓存的开源库,它不仅能实现平滑的图片列表滚动效果,还支持远程图片的获取.大小调整和展示,并且可以加载GIF图片.Glide相比与U ...