随笔分类 -  POJ

摘要:/*有一个农夫要把一个木板钜成几块给定长度的小木板,每次锯都要收取一定费用,这个费用就是当前锯的这个木版的长度给定各个要求的小木板的长度,及小木板的个数n,求最小费用38 8 5为例:长度为 21 的木板,截成13和8花费 21再从长度为13的木板上锯下长度为5的木板,花费13 共21+13 =34*/#include <iostream>#include <queue>#include <vector>using namespace std;int main(){ int i,j,k,T; __int64 num,sum=0; while(cin>& 阅读全文
posted @ 2012-08-08 16:25 加拿大小哥哥
摘要:#include <iostream>#include <string>#include <map>#include <iterator>#include <cstdio>using namespace std;int main(){ string s; int cnt=0; map<string,int> tree;//一对一映射 while(getline(cin,s)) { tree[s]++;//数组方式 cnt++; } map<string,int>::iterator iter; for(iter 阅读全文
posted @ 2012-08-07 23:44 加拿大小哥哥
摘要://由先中序建树,然后后序遍历 #include <cstring>#include <string>#include <iostream>#include <cstdlib>using namespace std;typedef struct Node{ char data; Node *lchild,*rchild;}Node,*Bitree;Bitree creat(string s1,string s2){ if(s1.length()==0)//到叶子节点 return NULL; Node *root = new Node; if(! 阅读全文
posted @ 2012-08-07 13:19 加拿大小哥哥
摘要:/*字符串匹配,(模式串 主串)区分大小写*/ #include <cstdio>#include <cstring>#include <cstdlib>using namespace std;const int N = 100010;char str1[N],str2[N];bool is_match(){ int i,j; if(strlen(str1)>strlen(str2)) return false; for(j=i=0;str1[i]!='\0'&&str2[j]!='\0';j++) if 阅读全文
posted @ 2012-08-07 00:07 加拿大小哥哥
摘要:Round and Round We GoTime Limit: 1000MSMemory Limit: 10000KTotal Submissions: 10514Accepted: 4812DescriptionA cyclic number is an integer n digits in length which, when multiplied by any integer from 1 to n, yields a"cycle"of the digits of the original number. That is, if you consider the 阅读全文
posted @ 2012-08-06 23:06 加拿大小哥哥
摘要:#include <cstdio>#include <cstring>#include <cctype>#include <cstdlib>using namespace std;char str[210];int main(){ int i,j,k,T; char str0[10]; while(scanf("%s",str0),strcmp(str0,"ENDOFINPUT")) { getchar(); memset(str0,0,sizeof(str0)); memset(str,0,sizeof( 阅读全文
posted @ 2012-08-06 18:52 加拿大小哥哥
摘要:RailsTime Limit: 1000MSMemory Limit: 10000KTotal Submissions: 18846Accepted: 7515DescriptionThere is a famous railway station in PopPush City. Country there is incredibly hilly. The station was built in last century. Unfortunately, funds were extremely limited that time. It was possible to establish 阅读全文
posted @ 2012-08-02 17:51 加拿大小哥哥
摘要:ZipperTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 13041Accepted: 4560DescriptionGiven three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in it 阅读全文
posted @ 2012-08-02 12:11 加拿大小哥哥
摘要:Recaman's SequenceTime Limit: 3000MSMemory Limit: 60000KTotal Submissions: 18575Accepted: 7751DescriptionThe Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsulting am is positive and not already in the sequence, otherwise am = am−1 + m. The first few numbers in 阅读全文
posted @ 2012-08-02 10:28 加拿大小哥哥
摘要:BabelfishTime Limit: 3000MSMemory Limit: 65536KTotal Submissions: 24748Accepted: 10586DescriptionYou have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.InputInput consist 阅读全文
posted @ 2012-08-01 16:53 加拿大小哥哥
摘要:/*大致题意:n个城市,先把1号断电,继而每隔m断电使标号为2的最后被限电;转化为(n-1)个城市,最后断电的为标号为1的城市,求最小的m*/ #include<stdio.h>bool is_joseph(int m,int n){ int i,j; int s=0; for(i=2;i<=n;i++) s=(s+m)%i; if((s+1)==1) return 1; return 0;}int main(){ int i,j,k; int m,n,s; while(scanf("%d",&n),n) { ... 阅读全文
posted @ 2012-08-01 10:21 加拿大小哥哥
摘要:JosephTime Limit: 1000MSMemory Limit: 10000KTotal Submissions: 40823Accepted: 15337DescriptionThe Joseph's problem is notoriously known. For those who are not familiar with the original problem: from among n people, numbered 1, 2, . . ., n, standing in circle every mth is going to be executed an 阅读全文
posted @ 2012-08-01 09:14 加拿大小哥哥
摘要:#include#includeint vis[310];void joseph(int n,int m){ int i,j,k; int cnt=0,count=0; memset(vis,0,sizeof(vis));//0表示未选中 for(i=1;count1)因为实际生活中编号总是从1开始,我们输出f[n]+1 由于是逐级递推,不需要保存每个f[i]*/ #include #includeint main() { int n,m,i,s=0; scanf("%d%d",&n,&m); for(i=2; i#include#inclu... 阅读全文
posted @ 2012-07-31 20:00 加拿大小哥哥
摘要:时间限制:1000ms内存限制:65536kB描述在 skew binary表示中, 第 k 位的值xk表示xk*(2k+1-1)。 每个位上的可能数字是0 或 1,最后面一个非零位可以是2, 例如, 10120(skew) = 1*(25-1) + 0*(24-1) + 1*(23-1) + 2*(22-1) + 0*(21-1) = 31 + 0 + 7 + 6 + 0 = 44. 前十个skew数是 0、1、2、10、11、12、20、100、101、以及102。输入输入包含一行或多行,每行包含一个整数n。 如果 n = 0 表示输入结束,否则n是一个skew 数输出对于每一个输入,输出 阅读全文
posted @ 2012-07-30 18:55 加拿大小哥哥
摘要:时间限制:1000ms内存限制:65536kB描述6*9 = 42 对于十进制来说是错误的,但是对于13进制来说是正确的。即, 6(13) * 9(13) = 42(13), 而 42(13) = 4 * 131 + 2 * 130 = 54(10)。 你的任务是写一段程序读入三个整数p、q和 r,然后确定一个进制 B(2#include#include#includeint vis[35];int vis_temp1[35];int vis_temp2[35];int max;long long My_Pow(int m,int n){ int i; int ans=1; ... 阅读全文
posted @ 2012-07-30 18:41 加拿大小哥哥
摘要:大致题意:给出自从2000 1 1过的天数,以-1结束,输出日期和星期//以后遇到闰年的问题,坚决用二维数组 #include<stdio.h>#include<string.h>#define N 10010char date[7][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};int vis[2][12]={31,28,3 阅读全文
posted @ 2012-07-30 09:57 加拿大小哥哥
摘要:字符串替换Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 7290Accepted: 3451Description编写一个C程序实现将字符串中的所有"you"替换成"we"Input输入包含多行数据 每行数据是一个字符串,长度不超过1000 数据以EOF结束Output对于输入的每一行,输出替换后的字符串Sample Inputyou are what you doSample Outputwe are what we do第一:#include<stdio.h> char 阅读全文
posted @ 2012-07-30 08:42 加拿大小哥哥
摘要:鲁宾逊先生有一只宠物猴,名叫多多。这天,他们两个正沿着乡间小路散步,突然发现路边的告示牌上贴着一张小小的纸条:“欢迎免费品尝我种的花生!——熊字”。鲁宾逊先生和多多都很开心,因为花生正是他们的最爱。在告示牌背后,路边真的有一块花生田,花生植株整齐地排列成矩形网格(如图1)。有经验的多多一眼就能看出,每棵花生植株下的花生有多少。为了训练多多的算术,鲁宾逊先生说:“你先找出花生最多的植株,去采摘它的花生;然后再找出剩下的植株里花生最多的,去采摘它的花生(也就是说,即便20不能被采摘,也不能采摘小于20的花生,最后的时间可能会剩余,这是不同于NYOJ 106贪心背包问题的);依此类推,不过你一定要在 阅读全文
posted @ 2012-07-27 17:50 加拿大小哥哥
摘要:u问题描述 •有一种特殊的日历法,它的一天和我们现在用的日历法的一天是一样长的。它每天有10个小时,每个小时有100分钟,每分钟有100秒。10天算一周,10周算一个月,10个月算一年。 •现在要你编写一个程序,将我们常用的日历法的日期转换成这种特殊的日历表示法。这种日历法的时、分、秒是从0开始计数的。日、月从1开始计数,年从0开始计数。秒数为整数。假设 0:0:0 1.1.2000 等同于特殊日历法的 0:0:0 1.1.0。 u输入 •第一行是一个整数 N ,表示测试样例的数目。每个测试样例包含一行,格式为:“hour:minute:second day.month.year”日期总是合法 阅读全文
posted @ 2012-07-27 11:18 加拿大小哥哥
摘要:大致题意:有一打(12枚)硬币,其中有且仅有1枚假币,11枚真币用A~L作为各个硬币的代号假币可能比真币略轻,也可能略重现在利用天枰,根据Input输入的3次称量,找出假币,并输出假币是轻还是重。#include<stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>int Abs(int a){ return a>0?a:(-a);}int vis[15];int main(){ int i,j,T,k;int ans; char str1[10],str2[10],str 阅读全文
posted @ 2012-07-26 20:26 加拿大小哥哥