07 2012 档案
usaco 2.4.1ttwo
摘要:水题,模拟题,贴代码,作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:ttwo 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h> 10 using namespace std; 11 12 int state[10][10][4][10][10][4]; 13 char grid[10][10]; 14 int cow[3]; 15 int farmer[3]; 1
阅读全文
usaco 2.3.1prefix
摘要:好吧,虽然很多人说这是很简单的DP题,但是对我来说还是蛮难的,从一开始的递归超时,到后来的DP超内存,再到后来的DP爆栈,直到现在才过。不过我知道这道题可以有很多种dp方法,还可以加上HASH,可以提速,不管怎么说,DP果然还是要更近一步啊!下面贴代码,以作纪念.View Code 1 /*{ 2 ID:jzy3209981 3 PROG:prefix 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h>1
阅读全文
usaco 2.3.5concom
摘要:还是水题,不过我承认代码写的很烂……下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:concom 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h>10 using namespace std;11 int control[101][101];12 int state[101][101];13 int sum[101];14 int main()15
阅读全文
usaco 2.3.3 zerosum
摘要:题目蛮简单,就是写起来蛮麻烦,可能有更好的写法。下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:zerosum 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h>10 using namespace std;11 12 char formula[20];13 14 bool caculate(int n)15 {16 int result=0,i,nu
阅读全文
usaco 2.3.2 nocows
摘要:坑爹!首先吐槽下,错了一个符号调试了我一个晚上!!然后想说DP方程有时候真不容易想出来…………下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:nocows 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h>10 using namespace std;11 12 int kind[200][100];13 int work(int n,int h)14
阅读全文
usaco 2.2.4 lamps
摘要:本来是蛮简单的题,但是没想到要按大小排序……所以取了点巧。有空会再研究下更好的方法。因为只可能有16种可能,所以枚举就可以了。下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:lamps 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h> 10 using namespace std; 11 12 bool lamb[110]; 13 int off[1
阅读全文
usaco 2.2.3 runround
摘要:蛮简单的题,直接枚举就行了,稍微剪枝,注意数字不能重复出现并且没有0.下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:runround 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h>10 using namespace std;11 12 13 int move(char *fin,int n,int len)14 {15 switch(fin[n
阅读全文
usaco 2.2.2 subset
摘要:这道题看起来蛮简单,却花费我不少时间,看来功夫还是不够啊。深搜超时、递归也超时,DP才能过,现在对DP理解更深了一次额。下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:subset 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h>10 using namespace std;11 12 int dp[40][800];13 int sum[40];1
阅读全文
usaco 2.2.1 preface
摘要:题目蛮简单,不过代码写的有点长,可能有更好的方法……下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:preface 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h> 10 using namespace std; 11 12 void t(int n,char ch[20]) 13 { 14 int i=0; 15 while(n!=0) 16 {
阅读全文
usaco 2.1.5 hamming
摘要:简单题,感觉很久没做过这么简单的题了。最小的数肯定是0,接下来枚举就行了。下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:hamming 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h>10 using namespace std;11 12 int bitnum(int n)13 {14 int i=0;15 while(n!=0)16 {17 n
阅读全文
usaco 2.1.4 holstein II
摘要:这是用dfs写出来的,照样调试用了很多时间,有待加强啊!!下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:holstein 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h>10 using namespace std;11 12 int scoop[15][25];13 int vitamin[25];14 int minn;15 int order
阅读全文
usaco 2.1.4 holstein
摘要:悲剧啊!这么简单的题想了一天愣是没想到,枚举就可以了…………dfs也可以,回去再写一遍。深刻的教训!!下面贴出代码,匆忙写出来的,没有优化代码,做个纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:holstein 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h>10 using namespace std;11 12 int scoop[15][25];13 int
阅读全文
usaco 2.1.3 sort3
摘要:简单题,用数学方法做出来的,有更好的方法,有时间研究。下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:sort3 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h>10 using namespace std;11 int num[1000];12 int sign[3][2];13 14 int main()15 {16 freopen ("
阅读全文
usaco 2.1.2 frac1
摘要:呃 貌似这道题有很好的方法,不过我已经用笨方法一次过了,就没有再多研究了。我的方法就是枚举加排列,用结构体存分子分母和值,遇到可以约分的略过……下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:frac1 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<math.h>10 using namespace std;11 12 13 struct fraction14
阅读全文
usaco 2.1.1 castle
摘要:虽然很多人说用广搜,但我使用深搜做的。因为是第二次写深搜,写的很烂也很麻烦,还写了很久,而且途中不免磕磕绊绊,虽然过了,但代码有待优化。本题依旧用了位运算,位运算好东西啊。下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:castle 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<stdlib.h> 10 #include<math.h> 11 usi
阅读全文
usaco 1.5.4 checker
摘要:终于到第一张最后一题了!不过最后一题果然有些难度,虽然是老问题“八皇后”,但是对于从没写过深搜的我来说还是一个挑战。好不容易花了很长时间写正确了深搜,结果也很在意料之中的超时,剪枝的话嫌太麻烦,于是去网上找优化方法,原来有一种叫做位操作的方法可以大大缩短时间,研究了一阵子才搞懂。这里感谢freddy's Blog,在那里借鉴了很多。我还会再改一改代码以更符合我的风格。下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:checker 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #includ
阅读全文
usaco 1.5.3 sprime
摘要:直接枚举,肯定超时,用dp做很简单。下面贴代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:sprime 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<stdlib.h>10 #include<math.h>11 using namespace std;12 13 int number[8][100]={{2,3,5,7,NULL}};14 char cpy[
阅读全文
usaco 1.5.2 pprime
摘要:本来也是很简单的题,可是调试花了我几个小时!!!问题很严重啊,那些小错误能把人气上天了,看来还要更仔细更耐心一点!代码写的不怎么样,因为很多小错误不得已用小代码改过去…………应该有改进的办法…………下面贴代码,以作纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:pprime 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 #include<stdlib.h> 10 #include<math.
阅读全文
usaco 1.5.1 numtri
摘要:很简单的递归,没什么好说的,贴代码,留纪念。View Code 1 /*{ 2 ID:jzy3209981 3 PROG:numtri 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 using namespace std;10 11 int numtriangle[1005][1005];12 int result[1005];13 int temporary[1005];14 15 void start(int n)16 {17 int i;
阅读全文
usaco 1.4.1 packrec
摘要:坑爹的题,居然让我写了800行代码还没过,只能重新写…………个人觉得老卡在这道题没什么意思,所以只是枚举着过了,,虽然过了,但是代码写的很烂,下面贴出代码,以作纪念.View Code 1 /*{ 2 ID:s42k5ek 3 PROG:packrec 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 using namespace std; 10 11 void paixu(int first[][2],int a,int b) 12 { 13
阅读全文
usaco 1.4.4 milk3
摘要:这道题很明显是模拟题,可惜我一开始还用枚举……悲剧的浪费了很多时间。还有就是,模拟要模拟一切情况并且保证模拟的结果的正确性,这道题主要花费的时间集中在纠正小错误和发现新情况没有模拟到这些问题上,是一道警醒题!我相信这道题肯定有人比我模拟的好,也能用枚举做出来(可能很麻烦)……下面贴出代码,以作纪念。View Code 1 /*{ 2 ID:s42k5ek 3 PROG:milk3 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 using nam
阅读全文
usaco 1.4.3 ariprog
摘要:看题很容易让人用暴力搜索,再加上剪枝,信心满满地交了题,结果TLE了,绞尽脑汁继续剪枝终于从卡在TEST 6转变为卡在TEST 8了,结果还是TLE …………,某位高人指点,豁然开朗,用空间换时间!!于是 ,每个测试都只是很短的时间…………这样看来,搜索出了剪枝特别重要外,有时候要考虑考虑空间换时间,比如爆搜,或者深搜,也可以考虑时间款空间,比广搜变成广搜深搜结合……下面贴出代码,以作纪念:View Code 1 /*{ 2 ID:s42k5ek 3 PROG:ariprog 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<io
阅读全文
usaco 1.4.2closks
摘要:这道题不同人有不同说法,有人说这道题表面看起来像BFS,其实用了才知道会MLE;但另外有人说这道题是典型的BFS题……本着既然有人能做出来的原则,还是用BFS做出来了,做出来才明白剪枝该有多重要……以后分析要尽可能彻底些。下面贴出代码,以作纪念:View Code 1 /*{ 2 ID:s42k5ek 3 PROG:clocks 4 LANG:C++ 5 }*/ 6 #include<stdio.h> 7 #include<iostream> 8 #include<string.h> 9 using namespace std; 10 11 int a[3]
阅读全文
浙公网安备 33010602011771号