hdu 3450
摘要:吐吐槽吧:本来思路完全对了,但是那个二分查找搞错了,我还以为一个就可以了,结果查找上界和下界分别要一个查找函数(WA时就看了一下别人的代码,发现别人都是用两个查找函数的,模仿别人写的查找函数),自己得好好揣摩揣摩。。。还有就是最后的结果可能是负数。。。因为get_sum的值是小于9901的,而N的值可大于9901代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 const int mod = 9901; 6 const int maxn = 100000 + 1
阅读全文
posted @
2012-04-30 16:55
Shirlies
阅读(309)
推荐(0) 编辑
uva 515
摘要:这一题是访别人写的,第一道差分约束的题目,但是现在做一题就得整理模板了。。。至少把它的思想好好记住http://blog.sina.com.cn/s/blog_60707c0f0100xht7.html这个讲差分约束的,算法导论上面也有,还是比较喜欢看纸质版的。代码来自http://www.cnblogs.com/staginner/archive/2011/10/20/2218421.html
阅读全文
posted @
2012-04-20 15:31
Shirlies
阅读(193)
推荐(0) 编辑
uva 10986
摘要:最短路Dijkstra算法,用优先队列。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 #include <vector> 5 using namespace std; 6 7 const int maxn = 50010; 8 struct node 9 {10 int v;11 int w;12 };13 14 typedef pair<int,int> pii;15 vector<node> p[2*maxn];16 int
阅读全文
posted @
2012-04-18 17:14
Shirlies
阅读(358)
推荐(0) 编辑
uva 10801【Lift Hopping】
摘要:表示对这类题目没feel,抽象。。。参考别人的代码后写出来的,顺便练习了一下FIFO队列实现Bellman-ford算法。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <queue> 4 #include <cmath> 5 using namespace std; 6 7 int g[6][105]; 8 int n,k; 9 int t[6];10 int d[105];11 int v[105];12 13 void init()14 {15 for(int i =
阅读全文
posted @
2012-04-17 21:09
Shirlies
阅读(265)
推荐(0) 编辑
uva 10099【The Tourist Guide】
摘要:忠诚的告诉大家:uva上的题目一定要看清楚格式啊,格式错误也是WA啊,~~~~(>_<)~~~~ 因为一个换行符WA了几次。。。Dijkstra的变形。。。求一条路上的最小值然后取多条路中的最大值。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 int g[110][110]; 6 int v[110],d[110]; 7 int N,R; 8 int start,end,per; 9 int cas;10 11 bool init()12 {
阅读全文
posted @
2012-04-17 19:53
Shirlies
阅读(234)
推荐(0) 编辑
uva 10369【Arctic Network】
摘要:模板题目了,又一个Krustral变形。。。题意:给你P个点,目前有S个卫星频道(satellite channels),求一条边在连接后中的图中是最大的,但是要求是所用方案中最小的,明显的最小生成树。求最小生成树中最长的那条边就可以了,但是那些最长的边可以卫星通讯(Any two outposts with a satellite channel can communicate via the satellite,其实这里还是有一个疑问的:要是a,b用卫星频道,c,d也用卫星频道,那么如果这两段不用radio是不是也可以通讯啊,根据题意应该是不可以的,如果可以就A不了了),所以求第P-S条最
阅读全文
posted @
2012-04-16 16:42
Shirlies
阅读(628)
推荐(1) 编辑
uva 10397【Connect the Campus】
摘要:Krustral 变形。。。。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <cmath> 5 6 struct distance 7 { 8 int u,v; 9 double w;10 }d[1000000];11 12 struct point13 {14 int x,y;15 }p[1000];16 17 int f[1000];18 int n;19 int num;20 21 bool cmp(const dista
阅读全文
posted @
2012-04-16 13:02
Shirlies
阅读(208)
推荐(0) 编辑
uva 10048【Audiophobia】
摘要:这一题不错。。。将floyd变了变形。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 int point,street,que; 6 int g[1010][1010]; 7 int cas; 8 9 bool init()10 {11 scanf("%d%d%d",&point,&street,&que);12 if(point == 0&&street == 0&&que ==
阅读全文
posted @
2012-04-16 11:16
Shirlies
阅读(228)
推荐(0) 编辑
uva 10034【Freckles】
摘要:Krustral是也。。。View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <cmath> 5 6 struct segment 7 { 8 int u,v; 9 double w;10 }s[10000];11 12 struct point13 {14 double x,y;15 }p[110];16 17 int f[105];18 int n;19 int sum;20 double len;21 22 bool cmp
阅读全文
posted @
2012-04-15 23:30
Shirlies
阅读(269)
推荐(0) 编辑
uva 567【Risk】
摘要:求最短路,Floyd算法,简单的应用不过题目真的很晦涩。。。第一个数x表示与第i个数(通俗一点,第i行,其实也是标号为i的点)相邻的点的个数,然后后面有x个值。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 int g[22][22]; 6 int n; 7 8 bool init() 9 {10 int num;11 for(int i = 1;i <= 20;i ++)12 {13 for(int j = 1;j <= 20;j ++)14 .
阅读全文
posted @
2012-04-15 21:27
Shirlies
阅读(262)
推荐(0) 编辑
uva 10717【Mint】
摘要:这一题做的有点小苦,但是最终取得了成功,(*^__^*) 嘻嘻……起初不知道哪里出问题了,一直WA,然后对照网上的代码一步一步的改啊,提交啊,最终AC了,然后又一步一步的改回到自己原来的样子,(~ o ~)~zZ错误找到了。。。不知道WA了多少次,又AC了多少次,不计算了,而且我的代码运行时间比网上的代码时间更短,成就啊,不过有点小浪费空间,其实两个循环可以合并,就少一点空间了。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 int length[60];
阅读全文
posted @
2012-04-15 13:06
Shirlies
阅读(326)
推荐(0) 编辑
uva 10791【 Minimum Sum LCM】
摘要:每做一题就对数学更加崇拜!看了别人做的才会做的,细节问题不会处理http://www.mysjtu.com/page/M0/S653/653211.html还是贴上自己的代码吧。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 5 int n; 6 7 long long solve() 8 { 9 int m = (int)sqrt(n + 0.5);10 long long sum = 0;11 int count = 0;12 for(int i = 2;i &l
阅读全文
posted @
2012-04-14 17:40
Shirlies
阅读(192)
推荐(0) 编辑
uva 11121【base -2】
摘要:uva上面的题目就是不一样啊。。。表扬一下“经典”。。。代码如下: 1 #include <cstdio> 2 #include <cstring> 3 4 int a[100]; 5 int n; 6 void solve() 7 { 8 memset(a,0,sizeof(a)); 9 int len = 0;10 while(n!=0)11 {12 a[len] = (n%2 + 2)%2;//这个取模的方法很有用13 n = (n - a[len ++])/(-2);14 }15 if(len == 0)...
阅读全文
posted @
2012-04-14 15:20
Shirlies
阅读(185)
推荐(0) 编辑
uva 106【Fermat vs. Pythagoras】
摘要:神奇的一题,偶对数学的崇拜加深了!题解:http://www.algorithmist.com/index.php/UVa_106我自己再简单的解释一下吧。。。x2+y2=z2(这些都是在x,y,z互质的情况下推的),可以变成:y2=(z - x) * (z + x),我们再变换一下:(y/2)2 = (z - x)/2 * (z +x )/2 ((z-x)/2和(z + x)/2必然为平方数,因为(z - x)/2和(z + x)/2必然是互质,没有共同的因子,自己可以好好想想,推一推) ,设r2 = (z - x)/2,s2 = (z +x )/2,前面是在互质的情况下退出来的,但是反推的
阅读全文
posted @
2012-04-14 12:01
Shirlies
阅读(462)
推荐(0) 编辑
uva 10006
摘要:一题如此基础的题目,搞了那么久,晕。。。不过有很多细节错误自己改过来了,给自己鼓鼓掌^_^求幂的时候要用longlong型的,可是为什么啊?x的值根本就不可能比65000大啊,每次都取模啊,求反例。。。。。。还有判断素数要在前,刘汝佳先生说过&&是短路来着。。。。。。View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 5 int prime[65002]; 6 int n; 7 8 void is_prime() 9 {10 int m = sqrt(
阅读全文
posted @
2012-04-13 20:27
Shirlies
阅读(639)
推荐(0) 编辑
poj 1696
摘要:不错的一题,需要极角排序,看了别人的代码做的。。。。。。计算几何啊~~~View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <algorithm> 5 6 const double er = 1e-8; 7 struct point 8 { 9 int index;10 int x,y;11 }p[100];12 int n;13 int res;14 15 int dis(point a,point b)16 {17 return sq
阅读全文
posted @
2012-04-12 10:43
Shirlies
阅读(247)
推荐(0) 编辑
uva 10405
摘要:晕,最基本的dp题,最长公共子序列。。。。。。竟然没有考虑到空格,衰衰地wa了几次。。。。。。View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 5 const int maxn = 1010; 6 int dp[maxn][maxn]; 7 char s1[maxn]; 8 char s2[maxn]; 9 10 int main() 11 { 12 while(gets(s1) != NULL) 13 { 14 gets(s2); 15 int len1
阅读全文
posted @
2012-04-07 16:20
Shirlies
阅读(407)
推荐(0) 编辑
uva 103
摘要:(~ o ~)~zZ最长子序列。。。。。。View Code 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 struct box 7 { 8 int index; 9 int dm[12]; 10 }b[40]; 11 int num,dim; 12 int ins,maxn; 13 int dp[40]; 14 int record[40]; 15 int ans[40]; 16 17 bool cmp(const box
阅读全文
posted @
2012-04-07 15:49
Shirlies
阅读(287)
推荐(0) 编辑
uva 111
摘要:这一题题意理解起来有点困难,汗,这个对题目意思解释比较详细,我是看了这个题目解释才做出来的http://www.byywee.com/page/M0/S259/259491.htmlView Code 1 #include <cstdio> 2 #include <cstring> 3 4 int in[30]; 5 int right[30]; 6 int dp[30]; 7 int b[30]; 8 9 int main() 10 { 11 int n; 12 int a; 13 scanf("%d",&n); 14 for(int i
阅读全文
posted @
2012-04-07 11:23
Shirlies
阅读(345)
推荐(0) 编辑