![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
ZOJ
Iamallblue
这个作者很懒,什么都没留下…
展开
-
zoj 3839(ZOJ Monthly, November 2014)
J.Poker Face递归求解#include using namespace std;#define maxn 1024char ch1[maxn+1][maxn+1];char ch2[maxn/2+1][maxn/2+1];void init(){ memset(ch1,' ',sizeof(ch1)); memset(ch2,' ',s原创 2014-12-01 00:04:08 · 564 阅读 · 0 评论 -
zoj 1602 Multiplication Puzzle
d[i][j]:在区间a[i]~a[j]范围内能取到的最大值d[i][j]=min{d[i][k]+a[k]*a[k+1]*a[k+2]+d[k+2][j]} i+1=#includeusing namespace std;#define maxn 105int d[maxn][maxn];int n;int a[maxn];int dp(int l,int r)原创 2015-01-22 20:51:53 · 322 阅读 · 0 评论 -
zoj 1642 Match for Bonus
最长公共子串的变形#include using namespace std;int ch[1000];int d[2005][2005];int main(){ int n; while(scanf("%d",&n)!=EOF){ char cc;int a; memset(ch,0,sizeof(ch)); for (int i=0;i<n;i++){ /原创 2015-01-22 20:54:20 · 378 阅读 · 0 评论 -
zoj 1666 Square Coins
d[s]:凑齐s值的方法数d[s]=sum(d[s-i*i])1=#include using namespace std;int main(){ int n; int d[305]; memset(d,0,sizeof(d)); d[0]=1; for (int i=1;i<=17;i++){ for (int s=i*i;s<=300;s++){ d[s]原创 2015-01-22 20:58:28 · 349 阅读 · 0 评论 -
zoj 1733 Common Subsequence
最长公共子串#include using namespace std;char a[1005],b[1005];int d[1005][1005];int main(){ while(scanf("%s%s",a,b)!=EOF){ int len1=strlen(a); int len2=strlen(b); memset(d,0,sizeof(d)); for原创 2015-01-22 21:02:17 · 388 阅读 · 0 评论 -
zoj 1629 Counting Triangles
可以轻易的知道以某个小三角行为顶点的三角形的个数,然后再求和即可#include using namespace std;int main(){ int n; while(scanf("%d",&n)!=EOF){ int sum=0; for (int i=1;i<=n;i++){ sum+=i*(n-i+1); } for (int i=1;i<n;i++)原创 2015-01-22 21:06:10 · 330 阅读 · 0 评论 -
zoj 1713 Haiku Review
水题,但是我从别人的博客那里学来了新的读入方式,可以简化操作#include using namespace std;int is(char c){ switch (c) { case 'a':return 1; case 'e':return 1; case 'i':return 1; case 'o':r原创 2015-01-22 21:00:26 · 514 阅读 · 0 评论 -
zoj 1159 487-3279
简单字符串处理,wa了十几次后发现是自己最后的空格格式控制出了错,晕tmd,不管wa了多少次,我也一定要ac#include using namespace std;string dd[1000];void init(){ dd['1']="1";dd['0']="0"; dd['2']=dd['A']=dd['B']=dd['C']="2"; dd['3']=dd['D']原创 2015-01-26 12:55:54 · 375 阅读 · 0 评论 -
zoj 1520 Duty Free Shop
题意:Pedro有2种巧克力分别有m块和 l块,现在他有n个巧克力盒子,他希望把这n个盒子全都填满,要求每种盒子中只能包含有一种巧克力,巧克力可以有剩余,如果能填满,就输出第一种巧克力用了多少个盒子,并且输出盒子的序号,如果不能就输出Impossible to distribute0,1背包m[s]:表示s这个数能否被填满m[s]=m[s]|m[s-d[i]]求出第一种巧克力最多能原创 2015-01-24 16:18:21 · 490 阅读 · 0 评论 -
zoj 1738 Lagrange's Four-Square Theoremdon
动态规划d[s]:组成s值的方法数d[s]+=d[s-i*i]#includeusing namespace std;#define N 40000int main(){ int n; int d[1<<16][5]; memset(d,0,sizeof(d)); d[0][0]=1; for(int i=1;i*i<N;i++) for(int j=1;j<原创 2015-01-24 16:22:33 · 408 阅读 · 0 评论 -
zoj 1788 Quad Trees
题意:对于一个0,1矩阵,如果该矩阵全都是一种颜色,那么就在树上表示为(0,1)or(0,0)第二个值看对应区域的颜色是0还是1了,如果颜色不同就在树上标记为1,并且继续细分直到该区域颜色全都相同为止,分法就是把当前区域平均分成4份,如图所示。求,对于的树的从上倒下,把数据写成一排,如题目图的树,每层分别为,1,001011,000110000000101,00010001,连接在一块就成了一原创 2015-01-24 16:31:51 · 1308 阅读 · 0 评论 -
zoj 1276 Optimal Array Multiplication Sequence
dp,经典问题了注意乘号两边都有空格#include using namespace std;struct node{ int l,r;};node m[15];int n;int d[15][15];int r[15][15];int dp(int i,int j){ if (d[i][j]>0) return d[i][j]; if (i==j) ret原创 2015-03-07 15:19:32 · 361 阅读 · 0 评论 -
zoj 1503 One Person "The Price is Right"
题目大意:给出g次选择机会,l次选择可以大于目标值,问最大可以选择的范围是多少d[i][j]:=还剩下i次选择,其中j次可以大于目标值的机会的最大选择范围可知,当下次随便选第k个值时,左边的1到k-1应该要等于d[i-1][j-1],k+1到n应该等于d[i-1][j]d[i][j]=d[i-1][j-1]+d[i-1][j-1]+1;#include using namespa原创 2015-03-06 13:17:29 · 407 阅读 · 0 评论 -
zoj 1366 Cash Machine
背包问题,二进制分割#include using namespace std;int main(){ int crase,nn; while(~scanf("%d%d",&crase,&nn)){ int dd[10005]; int num=0; for (int i=0;i<nn;i++){ int n,d; scanf("%d%d",&n,&d); i原创 2015-03-07 13:48:52 · 461 阅读 · 0 评论 -
zoj 1489 2^x mod n = 1
题目大意:给定一个n,求出最小的x满足2^x%n==1,如过存在就输出x不存在就输出?首先这题我们可以很直观的看出,n若为偶数,则必定不存在,因为2^x必定为偶数,偶数对偶数取余,不可能为奇数那么接下来就只用看n为奇数的情况了,其实n为奇数的时候一定存在,现在给出证明根据鸽巢原理,可知一定存在同余的情况假设2^x2>2^x1,且同余数,则有(2^x2-2^x1)%n==02^x原创 2015-03-20 20:17:19 · 627 阅读 · 0 评论 -
zoj 1425 Crossed Matchings
d[i][j]:=第一行的前i个与第二行的前j个匹配的最大值d[i][j]:=max(d[i-1][j],d[i][j-1],d[s1-1][s2-1]+2)1a[s1]==b[j],a[i]==b[s2],a[i]!=b[j]#include using namespace std;int main(){ int m; scanf("%d",&m); while(m-原创 2015-03-11 17:13:01 · 471 阅读 · 0 评论 -
zoj 1524 Supermarket
给定一个表单要求顺序购买,求最小的花费d[i][j]:=在前j个商家购买前i件物品的最小花费d[i][j]=min(d[i][j-1],d[i-1][j-1]+price[j]);其中第j个厂商卖的是第i件物品滚动数组优化空间原创 2015-03-11 20:24:02 · 342 阅读 · 0 评论 -
zoj 1539 Lot
#include using namespace std;int dfs(int n){ if (n<=5){ if (n<3) return 0; if (n==3) return 1; if (n==4) return 0; if (n==5) return 1; } if (n&1){ return dfs(n/2)+dfs(n/2+1); } els原创 2015-01-22 20:47:21 · 463 阅读 · 0 评论 -
zoj 1136 Multiple
a%n==x(a*10+b)%n==(x*10+b)%b要用数组存下余数优化,如果遇到余数为0代表算对了当所有的余数都算了,就是没有0的时候,就直接输出0#include using namespace std;struct str{ string s; int res;};int cmp(str a,str b){ return a.res<b原创 2015-01-17 23:30:01 · 361 阅读 · 0 评论 -
zoj 2402 Lenny's Lucky Lotto Lists
zoj 2402 Lenny's Lucky Lotto Lists动态规划原创 2015-01-08 19:22:51 · 375 阅读 · 0 评论 -
zoj 2405 Specialized Four-Digit Numbers
zoj 2405 Specialized Four-Digit Numbers水题原创 2015-01-08 19:27:06 · 353 阅读 · 0 评论 -
zoj 1178 Booklet Printing
之所以这题要写博客,那是因为这题真是坑出翔要不是我眼尖不知道又要wa多少次了你能想象back前比front多了一个空格吗?为此我找了好久的错#include using namespace std;struct sheet{ int front1,front2; int back1,back2;};int main(){ int n; while原创 2015-01-27 20:33:00 · 514 阅读 · 0 评论 -
zoj 2401 Zipper
zoj 2401 Zipper动态规划原创 2015-01-08 21:13:26 · 1954 阅读 · 0 评论 -
zoj 1905 Power Strings
#include using namespace std;char a[1000005];int len;int check(int lens){ for (int i=0;i<len;i+=lens){ for (int s=0;s<lens;s++){ if (a[s]-a[s+i]!=0){ return 0; } } } return 1;}原创 2015-01-28 22:20:29 · 376 阅读 · 0 评论 -
zoj 1090 The Circumference of the Circle
zoj 1090 The Circumference of the Circle计算几何原创 2015-01-16 12:42:20 · 405 阅读 · 0 评论 -
zoj 1042 W's Cipher
zoj 1042 W's Cipher模拟原创 2015-01-16 12:05:52 · 475 阅读 · 0 评论 -
zoj 1092 Arbitrage
找到这样一个环,使得钱能越变越多找最长路,d[i][i],正好表示从i出发回到i的最长的路然后找到这样一个路后判断知否存在大于1的情况#include using namespace std;int n;char as[35][100];double dd[35][35];int findd(char k[]){ for (int i=0;i<n;i++){原创 2015-01-16 21:02:59 · 395 阅读 · 0 评论 -
zoj 1082 Stockbroker Grapevine
zoj 1082 Stockbroker Grapevinedp,最短路原创 2015-01-16 16:43:24 · 354 阅读 · 0 评论 -
zoj 1067 Color Me Less
zoj 1067 Color Me Less原创 2015-01-16 12:07:54 · 328 阅读 · 0 评论 -
zoj 1081 Points Within
判断点是否在多边形内、模版题、我也只会套模版了、、#include using namespace std;const int maxn=105; //多边形点的个数const double eps=1e-8;int cmp(double x){ if (fabs(x)<eps) return 0; if (x>0) return 1; return -1;原创 2015-01-16 22:55:38 · 306 阅读 · 0 评论 -
zoj 1108 FatMouse's Speed
这么简单的题,还写了好久,还错了,,代码能力太菜了,慢慢练,,求最长的上升子序列,不过有两个限制,体重要求严格下降速度严格上升代码是瞄了别人的,自己做了写注释吧,,#include #include #include #include #include #include #define N 1010using namespace std;typedef struct转载 2015-01-17 18:00:30 · 323 阅读 · 0 评论 -
zoj 1149 Dividing
求可行性解的问题,多重背包解一开始直接上多重背包一般解法,先是wa,然后TL了,后来又试了别的方法,wa,再上网搜了下看了别人的,后来改用的二进制拆分//二进制拆分#include using namespace std;#define maxn 300050int d[maxn];//存可行性解的int n[7]; //存每种物品存放了多少个int num[ma原创 2015-01-18 16:42:39 · 320 阅读 · 0 评论 -
zoj 1196 Fast Food
题目大意:给定n个餐馆位置,要求在n个餐馆中选择m个作为仓库,使得总距离最小d[i][k]:在前i个餐馆中选择k个作为仓库的最小总距离d[i][k]=min(d[i][k],d[s][k-1]+MinDis(s+1,i));MinDis(s+1,i) :在s+1到i中选择一个餐馆作为仓库的最小距离#include using namespace std;#define max原创 2015-01-19 10:44:17 · 557 阅读 · 0 评论 -
zoj 1234 Chopsticks
#include using namespace std;#define maxn1 5005#define maxn2 1100int d[maxn1][maxn2];int p(int a){ return a*a;}int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",s原创 2015-01-19 16:26:00 · 445 阅读 · 0 评论 -
zoj 1454 Employment Planning
d[i][j]:=第i个月雇佣j名工人的最小开支#include using namespace std;int h,s,f;int dd(int data){ if (data==0) return 0; if (data<0) return -f*data; if (data>0) return h*data; }int main(){ int n;原创 2015-03-10 20:06:40 · 321 阅读 · 0 评论