随笔分类 -  USACO

摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1839将乱序的数列中的元素两两交换,变成升序数列,输出所需最小步骤数其实就是模拟一个过程,只有三种数,先是找只需交换一次便归位的,然后是交换两次三个数归位的,交换时计数就行 1 #include <iostream> 2 #include <algorithm> 3 #include <vector> 4 5 using namespace std; 6 vector<int> num,con(4); 7 int n,con_num; 8 9 void sw 阅读全文
posted @ 2013-03-09 19:08 tjsuhst 阅读(336) 评论(0) 推荐(0)
摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1838笨办法先列出所有分母不大于n的真分数,用二维数组储存,然后按分数大小排序输出的时候按顺序来,选gcd(分子, 分母)=1的输出 1 #include <iostream> 2 #include <algorithm> 3 #define MAX 160 4 using namespace std; 5 6 int n; 7 int **f=new int *[MAX*(MAX-1)/2+2]; 8 9 bool cmp(int *a,int *b)10 {11 double 阅读全文
posted @ 2013-01-29 22:30 tjsuhst 阅读(308) 评论(0) 推荐(0)
摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1832对于搜索不够敏感,其实与状态有关的,且存在状态改变的,都可以考虑一下搜索这题就是DFS给出A,B,C三个桶的大小,(0,0,C)——也就是说C桶是满的,从这个状态开始互相倒来倒去,输出A桶为0时,C桶可能的牛奶量 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int a,b,c,con; 6 bool s[21][21][21],flag[21]; 7 8 void dfs(in 阅读全文
posted @ 2013-01-29 21:32 tjsuhst 阅读(377) 评论(0) 推荐(0)
摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1836摆棋子,但是其横竖斜向均不可另有棋子,输出前三种解(按字典序输出),并输出总解数 1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 #define MAX 13 5 using namespace std; 6 7 int a[MAX]; 8 int n,con; 9 10 void print()11 {12 for(int i=0;i<n;i++)13 {14 cout 阅读全文
posted @ 2013-01-25 13:07 tjsuhst 阅读(381) 评论(0) 推荐(0)
摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1831先枚举公差,再枚举首项,这样可以直接输出在初始化中已经知道哪些数是双平方数,哪些不是 1 #include <iostream> 2 #include <algorithm> 3 #define MAX 250 4 using namespace std; 5 6 int n,m; 7 bool s[MAX*MAX*2+1]; 8 9 void ini()10 {11 int i,j;12 for(i=0;i<=m;i++)13 for(j=0;j<=m;j++) 阅读全文
posted @ 2013-01-24 17:45 tjsuhst 阅读(252) 评论(0) 推荐(0)
摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1826快排(用了两次,一次升序,一次降序,其实都用降序就行了)将牛棚间间隔最大的那几个减去即可,注意所需木板的最小总长应该是有牛的牛棚的个数,就这一点让我错了好多次 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int m,s,c,st[200]; 6 7 bool cmp1(int a,int b) 8 { 9 return a>b;10 }11 12 bool cmp2(in 阅读全文
posted @ 2013-01-23 15:49 tjsuhst 阅读(213) 评论(0) 推荐(0)
摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1825第一次用C++写,因为是对二维数组排序,所以先在网上了解了一下,这里二维数组用int **来表示了对于sort的用法还要深入了解思路就是先按单价排序,然后将数量一个一个加起来比较 1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 5 int n,m; 6 int **f=new int*[5000]; 7 8 bool cmp(int *a,int *b) 9 {10 if(a[0]== 阅读全文
posted @ 2013-01-22 16:49 tjsuhst 阅读(250) 评论(0) 推荐(0)
摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1824枚举,借用了“回文平方数”里的一些函数 1 #include<stdio.h> 2 #include<string.h> 3 4 char a[400]; 5 int n,s; 6 7 int exam() 8 { 9 int p1=0,p2=(int)strlen(a)-1;10 while(p1<p2)11 {12 if(a[p1]!=a[p2]) {return 0;break;}13 p1++;14 p2--;15 ... 阅读全文
posted @ 2013-01-22 14:55 tjsuhst 阅读(261) 评论(0) 推荐(0)
摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1823涉及到进制转换,要求输出在某进制下的回文数,用字符串处理会方便一些 1 #include<stdio.h> 2 #include<string.h> 3 4 char a[400]; 5 6 void swap() 7 { 8 int l=(int)strlen(a); 9 int p1=0,p2=l-1;10 int t;11 while(p1<p2)12 {13 t=a[p1];14 a[p1++]=a[p2];15 ... 阅读全文
posted @ 2013-01-22 13:36 tjsuhst 阅读(413) 评论(0) 推荐(0)
摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1820按开始时间排序,然后统计最长挤牛奶时间段和最长间隔段。快排又写错了一次...... 1 #include<stdio.h> 2 3 int a[5000][2],n; 4 5 int ones(int l,int r) 6 { 7 int i=l,j=r,flag=0,key=a[l][0]; 8 int t1,t2; 9 while(i<j)10 {11 if(0==flag)12 {13 if(a[j][... 阅读全文
posted @ 2013-01-22 12:26 tjsuhst 阅读(300) 评论(0) 推荐(0)
摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1833动态规划a[i][j]储存输入的金字塔,F[i][j]储存a[i][j]处能达到的最大值状态方程:F[i][j]=max{F[i+1][j], F[i+1][j+1]}+a[i][j] 1 #include<stdio.h> 2 int n; 3 int a[1000][1000]={0},F[1000][1000]={0}; 4 5 int main() 6 { 7 int i,j; 8 scanf("%d",&n); 9 for(i=0;i<n;i+ 阅读全文
posted @ 2013-01-20 10:48 tjsuhst 阅读(213) 评论(0) 推荐(0)
摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1819方法:枚举断点,注意全是w的情况 1 #include <stdio.h> 2 3 int nl[701];//necklace 4 int n;//珠子个数 5 6 int main() 7 { 8 int f1,f2,l1,l2,i=0; 9 int ca=0,cb=0,ans=0;10 char in[701];11 scanf("%d",&n);12 scanf("%s",in);13 for(i=0;i<n;i++)14 { 阅读全文
posted @ 2013-01-17 00:25 tjsuhst 阅读(334) 评论(0) 推荐(0)
摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1818又是水题,枚举每天的情况 1 #include <stdio.h> 2 3 int month[12]={31,28,31,30,31,30,31,31,30,31,30,31},week[7]; 4 int count,n; 5 6 int main() 7 { 8 int i=0,j=0,k=0; 9 scanf("%d",&n);10 count=1;//天数计数11 for(i=1900;i<1900+n;i++)12 {13 if... 阅读全文
posted @ 2013-01-15 01:10 tjsuhst 阅读(192) 评论(0) 推荐(0)
摘要:地址:http://hustoj.sinaapp.com/problem.php?id=1817一开始理解错题意,纠结好半天也不难,用最笨的办法,循环嵌套,一遍遍比对得出答案 1 #include <stdio.h> 2 #include <string.h> 3 4 char name[10][15]; 5 int gift[10][2],result[10]; 6 int n;//人数 7 8 int main() 9 {10 int i=0,j=0,k=0,l=0;11 char in[15];12 scanf("%d",&n);13 阅读全文
posted @ 2013-01-15 00:38 tjsuhst 阅读(404) 评论(0) 推荐(0)
摘要:从简单的开始地址:http://hustoj.sinaapp.com/problem.php?id=1816很简单,模拟题,注意一下范围即可,不过千万不能用fflush(stdin),要不然报错,这个可能和OJ本身有关 1 #include <stdio.h> 2 3 int main() 4 { 5 char in; 6 long long star=1; 7 long long group=1; 8 in=getchar(); 9 while(in>='A' && in<='Z')10 {11 star=star*(i 阅读全文
posted @ 2013-01-14 23:29 tjsuhst 阅读(283) 评论(0) 推荐(0)