摘要: 是一个水题。给一个数字n,计算出两个素数,使得他们的和等于n若没有则输出"Goldbach's conjecture is wrong."可以先做一个素数表,然后再枚举看2到n/2之间是否有满足条件的素数对。 阅读全文
posted @ 2011-04-20 19:53 watana 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 这个题目是黑书上面作为贪心算法的例题,就是枚举最远到X湖时,最多的钓鱼数,减掉在路上的时间,就相当于在湖点之间的瞬移。再从1到N个湖枚举,可以得到一个最优的序列。还有一些测试数据。#include<iostream>#include<cstring>#include<cstdio>using namespace std;struct lakes{ int f,d,t;}l[30],ll[30];int tmax[30],tt[30],fishmax;int main(){ //freopen("/home/master/文档/workspace/i 阅读全文
posted @ 2011-04-20 19:45 watana 阅读(389) 评论(0) 推荐(0) 编辑
摘要: 可以用动态规划做,但是简单的贪心就足够了。按照结束的位置排序,然后选择最长的。#include<iostream>#include<algorithm>using namespace std;struct exon{ int begin,end; int index;};int cmp(exon a,exon b){ return a.end<b.end;}int main(){ int n,i; exon e[1001]; while(cin>>n&&n!=0) { for(i=0;i<n;i++) { cin>>e 阅读全文
posted @ 2011-04-18 15:06 watana 阅读(191) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1047按照某大牛总结的一条规律,对于数N,若N为循环的则有N*(length(N)+1)=99....99, (length(N)个9),length(N)为N的位数,含前导0。应该还是简单的...还有POJ是什么时候换网址的...= =b#include<iostream>#include<string>using namespace std;bool fun(string str){ int n=str.length()+1; int i,up=0,temp=0; for(i=n-2;i>=0;i--) { 阅读全文
posted @ 2011-03-16 16:23 watana 阅读(356) 评论(0) 推荐(0) 编辑
摘要: http://acm.timus.ru/problem.aspx?space=1&num=1010方法一:单纯的枚举枚举每两点对,判断是否两点间的点都此两点的连线下方,计算斜率,找出最佳点对时间复杂度:O(N2) 方法二:改进后的枚举对方法一进行改进,是否可以从某种角度,找出突破点,减少枚举量呢?从数学角度入手,发现只有两点相邻,斜率能取得最大值,这样,只枚举相邻点即可时间复杂度:O(N)数据依然变态,听说全是longint的数据...我就用double过了...#include<stdio.h>#include<math.h>int main(){ int i 阅读全文
posted @ 2011-03-15 19:57 watana 阅读(207) 评论(0) 推荐(0) 编辑
摘要: http://acm.timus.ru/problem.aspx?space=1&num=1011本来就是个枚举的题目,但是俄罗斯人的数据果然很刁....如果先把P,Q转化为小数就会精度不够而在Test14出现WA...= =b#include<iostream>using namespace std;int main(){ int x; double p,q,peo1,peo2; while(cin>>p>>q) { x=100; while(1) { peo1=x/p-(1e-7); peo2=x/q; if(int(peo2+1)<=in 阅读全文
posted @ 2011-03-15 18:44 watana 阅读(144) 评论(0) 推荐(0) 编辑
摘要: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3727值得注意的是,这个题目的input数据还需要先按check in进行排序。#include<iostream>using namespace std;class renter{ public: int in; int leave; int rnum;}r[104];int main(){ int n,m; int room[104],index[104]; while(cin>>n>>m) { if(n==0&&m== 阅读全文
posted @ 2011-03-15 15:39 watana 阅读(198) 评论(0) 推荐(0) 编辑