POJ 3111
摘要:题意:给定n个结点,每个结点有v,w两个值,求含k个结点的子集,使得sum(v)/sum(w)最大。题解:0,1分数规划,求g=sum(v)/sum(w)最大,二分枚举g的值,求sum(v-g*w)的最小值,即选出n个结点中v-g*w的最小的k个元素,加起来与0进行比较。0,1分数规划详情请参见OI论文《最小割模型在信息学竞赛中的应用》View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N=10000
阅读全文
POJ 1049
摘要:题意:模拟微处理机。题解:大模拟~View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cctype> 5 using namespace std; 6 char s[300]; 7 int pos; 8 char A,B; 9 char D_H(int x) 10 { 11 if(x<10) 12 return x+'0'; 13 else 14 return x-10+'A'; 15 } 16 i
阅读全文
POJ 1105
摘要:题意:给出一个深度为n的满二叉树(根节点为0层),每层都有一个变量xi,然后2^n叶子结点被赋值为0,1。然后给出m个给xi赋值的情况,遇到0就朝左孩子走,反之就右孩子,将遍历到的m个叶子结点输出来。题解:弄清满二叉树中左孩子就是now*2,右孩子为now*2+1,其他就是模拟了。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int main() 6 { 7 int n,ca=0; 8 while(scanf(&q
阅读全文
POJ 2424
摘要:题意:给出饭店来人的顺序与人数,按照三种类型去坐,如果等待时间超过半个小时,客人就会走,问最后能接待多少客人。题解:大模拟!View Code 1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<queue> 5 using namespace std; 6 struct data 7 { 8 int t; 9 bool operator<(const data &ne)const 10 { 11 return t>ne.t; 12 }
阅读全文
POJ 1589
摘要:题意:给出n个字符串,排成阵列,要求每行长度不超过60,且每列宽度为n个字符串中最长的那个的长度加2,最后一列就是最长的长度,要使行数尽可能少。题解:直接推导出最后需要多少行多少列,细心一点就没问题了。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 char file[102][102][65]; 6 struct data 7 { 8 char s[70]; 9 bool operator<(const da
阅读全文
POJ 3656
摘要:题意:扔石子打水漂游戏,四个参数评判好坏,跳跃次数,最后在水中位置,初始位置,和单步跳跃长度,除了最后一项,其他都是越大越好,求最好的扔法。题解:数据也太小了吧。。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 struct data 6 { 7 int ct,len,ip,sk; 8 bool operator<(const data &ne)const 9 {10 if(ct!=ne.ct)11 .
阅读全文
POJ 3326
摘要:题意:给出每个人在某台电脑的登录时间与下线时间,求在某个时间段某个人的上线时间。题解:大模拟~可以先记录每个人的上下线时间点,看做一个区间的左右界限,然后记录区间深度,如果到某个时间点时,区间深度大于0,就说明这个人在线,否则,就不在。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<vector> 5 using namespace std; 6 struct data 7 { 8 int p,t; 9 bool lg;10 dat
阅读全文
POJ 1974
摘要:题意:在n*m的地图上,一只虫子找地方睡觉,它一睡就会把自己拉伸到碰到砖块,问它睡觉地方种数。题解:两次sort,依次统计横着睡和竖着睡的种数。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 struct data 6 { 7 int x,y; 8 }po[140000]; 9 bool comp_x(data a,data b)10 {11 if(a.x!=b.x)12 return a.x<b.x;13 e
阅读全文
POJ 1786
摘要:题意:给定牌的顺序,然后依次摸牌,最后对每个人的手牌排序输出。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int po[4][14],mp[300]; 6 char getch[500]; 7 void print_1(int a[]) 8 { 9 for(int i=0;i<13;i++)10 printf("|%c %c",getch[a[i]%100],getch[a[i]%100
阅读全文
POJ 2799
摘要:题意:给出n个同属一个网络的IP地址,求其子网掩码以及网络地址。题解:只需知道子网掩码与ip地址按位与后等于同一个值,且子网掩码前面全是1,后面全是0即可。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 struct IP 6 { 7 int b[4]; 8 }po[1005]; 9 int lowbit(int x)10 {11 return x&(-x);12 }13 int lg(int x)14 {1
阅读全文
POJ 2654
摘要:题意:n个人两两玩剪刀石头布的游戏,每个人玩k次,求最后每个人的胜利次数/(胜利次数+失败次数)题解:细心一点就没什么问题了。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int win[105],lose[105]; 6 int comp(char s1[],char s2[]) 7 { 8 switch(s1[0]) 9 {10 case 'r':11 switch(s2[0])12 {1...
阅读全文
POJ 2363
摘要:题意:这是一个题意很拗口的一道题,就是给你k个数,m<n然后需要判断自n开始到k结束的每个数,如果含它及以前的m个数的平均值即为pm,前n个数平均值即为pn,如果pm>pn且上一个点不是pm>pn或者是第一个点,就输出BUY ON DAY ?,另一种情况也一样处理。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int main() 6 { 7 int k,n,m; 8 double pn,pm,a
阅读全文
POJ 2803
摘要:题意:字符串翻译,遇到词典库里的前缀和后缀就按照词典库把它改成相应的词语或句子。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 char pre[5][50]={ 6 {"anti"},{"post"},{"pre"},{"re"},{"un"} 7 }; 8 char pr[5][50]={ 9 {"aga
阅读全文
POJ 3781
摘要:题意/题解:像这种水题我都不好意思写题解的,但为了计算每天A题数目等等的,之后发了。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int main() 6 { 7 int T; 8 for(scanf("%d",&T);T;T--) 9 {10 int ca,a[12];11 scanf("%d",&ca);12 for(int i=0;i<10;i++
阅读全文
POJ 3994
摘要:题意/题解:大水题,不想说了。View Code 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 int main() 5 { 6 int ca=0,n; 7 while(scanf("%d",&n),n) 8 printf("%d. %s %d\n",++ca,(n%2==0)?"even":"odd",(3*n+1)/2/3); 9 return 0;10 }
阅读全文
POJ 3192
摘要:题意:给定n个DNA字符串,然后可以让两个DNA端点部分交叉,条件是这端点部分能够匹配。问将n个DNA连成一串的最小长度。题解:像这种n那么小的题就是在诱惑人去暴力,枚举n个DNA的构造顺序,然后依次连接。View Code 1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 bool vis[10]; 6 char s[10][10]; 7 int n,ans,per[10]; 8 void link(char s1[],char s2[
阅读全文
POJ 3475
摘要:题意:一个矩形盒子,一张矩形纸,要通过折叠然后使得纸能装进盒子中,求次数。题解:简单题,但是题无难易,悉以A之。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int main() 6 { 7 double a,b,c,d; 8 while(scanf("%lf%lf%lf%lf",&a,&b,&c,&d)!=EOF) 9 {10 int ans=0;11 if(a
阅读全文
POJ 3561
摘要:题意:给定一张n*m的图,上面有4种线段,'-','|','\','/',判断图上是否有且仅有一条这样的线段。题解:遍历每个点,如果不是空,就将它所在的直线给删掉,并且记录值加一,最后判断记录是否等于一即可。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 char map[20][20]; 6 int r,c; 7 int dr[200][2]; 8 v
阅读全文
POJ 2106
摘要:题意:bool表达式求值,V:true;F:false题解:堆栈+优先级判定View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cctype> 5 using namespace std; 6 const int N=1000; 7 char comp(char a,char b) 8 { 9 if(b=='\0')10 {11 if(a=='\0')12 return '=';13 el
阅读全文
POJ 1057
摘要:题意:模拟数据库系统,给你文件及其对应关系,画出图形。以f开头的是文件,以d开头的是文件夹,']'代表文件夹结束,'*'代表样例结束,'#'代表输入结束。题解:模拟。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<vector> 5 #include<string> 6 using namespace std; 7 const int N=10000; 8 struct d
阅读全文
|
|
|