- 博客(53)
- 收藏
- 关注
原创 POJ1125-Stockbroker Grapevine
2011/07/14 12:49#include#define N 105using namespace std;int n,d[N],w[N][N];const int INF = 0x7fffffff;void DFS(int s){ int i; for(
2011-07-14 12:48:26
160
原创 POJ1062-昂贵的聘礼
2011/07/14 12:46题目地址:http://poj.org/problem?id=1062#include#define N 105using namespace std;//Dijkstraconst int INF= 0X7fffffff;int
2011-07-14 12:46:39
227
原创 POJ3851-Wormholes
2011/07/14 12:41题目地址:http://poj.org/problem?id=3851#include#define N 501#define M 5500using namespace std;struct PATH{ int u, v;
2011-07-14 12:43:53
237
原创 POJ-1028 Web Navigation
2011-07-03 23:45题目地址:http://poj.org/problem?id=1028=========================================================================
2011-07-03 23:48:20
189
原创 FOJ 1005 Fast Food (DP)
2011-06-20 10:32:35题目地址:http://acm.fzu.edu.cn/problem.php?pid=1005#include#includeusing namespace std;int main(){ int n,k,i,j,r,testCase=0; int distance[201],min[31][201],o
2011-06-20 10:32:00
602
原创 POJ 1611 The Suspects(并查集)
2011-06-19 15:54:09 #include#define N 30010using namespace std;int parent[N],root[N];int Find(int x){ if(root[x]) return x; return (parent[x] = Find(parent[x]));}void Union(i
2011-06-19 15:54:00
148
原创 FOJ 1924 死锁(拓扑)
2011-06-18 00:41:15 地址:http://acm.fzu.edu.cn/problem.php?pid=1924#include#define N 1005using namespace std;int flag[N][N]={0},cnt[N]={0};int main(){ int i,j,p,r,e1,e2,n,c
2011-06-18 00:42:00
201
原创 数构作业-cards(并查集)
2011-06-17 23:15:08理好思路,在码代码!!!!! #include#include#define N 30010using namespace std;int par[N],cnt[N],root[N],count;int FIND(int x){ if(par[x]==x) return x; par[x] =
2011-06-17 23:15:00
168
原创 数构作业-contest(拓扑排序)
2011-06-10 16:59:05小小错误,让我蛋疼。。。。。。#include#define N 510using namespace std;int flag[N][N]={0},cnt[N]={0};int main(){ int i,j,w,l,n,m,count=0; scanf("%d%d",&n,&m); for(i=0;i<
2011-06-10 16:59:00
135
原创 计数问题(TLE)o(╯□╰)o
#include#define N 1000010#define ui64 int //unsigned __int64using namespace std;ui64 cnt[N];ui64 euler(int n){ ui64 euler=n,i,nn=n; if(n==1) return 1;
2011-06-08 20:50:00
162
原创 POJ 1012 Packets (简单贪心)
2011-06-05 15:08:37题目地址:http://poj.org/problem?id=1017就因为两个小错误,导致了无数WA, ~~~~(>_#includeusing namespace std;int main(){ int a[7]; while(1) { int flag=0; int i,ans=
2011-06-05 15:09:00
134
原创 POJ 1012 Joseph
2011-06-05 10:09:27#includeint test(int k,int m){ int i,j,l=k<<1; for(j=i=0;i<k;i++) { j=(j+m-1)%(l-i); if(j<k) return 0; } return 1;}int main(){ int k,i,a[15]; f
2011-06-05 10:09:00
129
原创 数构作业-relative(并查集)
<br /> 2011-06-02 13:05:05<br />#include<iostream>#define N 100010using namespace std;int n,m,rel[N];bool root[N];void init(){ int i; for(i=0;i<n;i++) rel[i]=root[i]=1;}int getRoot(int x){ while(!root[x]) x=rel[x]; return x;}
2011-06-02 13:04:00
165
原创 POJ 1182 食物链(并查集+向量)
<br />2011-06-01 22:02:11<br />题目地址:http://poj.org/problem?id=1182<br />#include<iostream>#define N 50010using namespace std;int animal[N],flink[N],n,r;bool root[N];void INIT(){ int i; for(i=1;i<=n;i++) { animal[i]=root[i]=1; fli
2011-06-01 22:02:00
265
原创 数构作业-dispatch(最小堆)
<br />2011-05-29 13:00:15<br />#include<iostream>#include<queue>#include<algorithm>#define N 200010using namespace std;struct Work{ int s, t; bool operator < (Work w) { return s<w.s; }} work[N];int main(){ priority_queue
2011-05-29 12:59:00
147
原创 数构作业-learning(最小堆)
<br />2011-05-28 17:42:33<br />#include<iostream>#define N 100010using namespace std;struct Student { int id, kn; bool operator <(Student t) { return kn>t.kn||(kn==t.kn&&id>t.id); }}stu[N];void SWAP(Student *s1,Student *s2){
2011-05-28 17:42:00
143
原创 数构作业-dota(散列表(实际用排序做的))
2011-05-23 22:11:44这一次就因为对STL里的sort函数理解不透,才导致过了两个点,八个TLE 囧·······听学长说,sort对结构体排序只重载了小于号(<),而我在写比较函数(cmp)的时候,对当两个结构体“相等“时令其返回1,相当于重载了小于等于号(~~~~(>_下面是TLE代码,把比较函数当结构体”相等“时返回1的情况改为返回0即可全AC#include#include#include#define N 200010using namespace std;
2011-05-23 22:17:00
186
原创 数构作业-train(散列表)
<br />2011-05-23 22:10:14<br />#include<iostream>#include<stdio.h>#include<set>#include<string>using namespace std;char str1[2][211],str2[2][211];int main(){ set<string> mySet; char str[211], temp[211]; int n,i,j,k,ll,x,len; while (
2011-05-23 22:10:00
168
原创 ZOJ 1610 Count The Colors(线段树)
2011-05-17 18:47:04#include#define N 16010struct Node { int l, r, color; Node *ls, *rs;}node[N];int resCol[8001],xx,col;Node* Build(int l,int r){ static int count=0; int mid=(l+r)>>1; Node* root=node+(count++); root->l=
2011-05-17 18:50:00
167
原创 POJ 3368 Frequent values(线段树)
<br />2011-05-17 10:50:08<br />题目地址;http://poj.org/problem?id=3368<br />#include<iostream>#include<stdio.h>#define N 100010using namespace std;struct Node { int l, r;}node[N];struct SegNode { int l, r, c; SegNode *ls, *r
2011-05-17 10:50:00
133
原创 Angry Bird(树状数组)
2011-05-16 19:58:17Problem 1002 愤怒的小鸟 Accept: 16 Submit: 54Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description《愤怒的小鸟》已经取代了《植物大战僵尸》,成为了iphone上最畅销的游戏。 这款游戏的故事相当有趣,为了报复偷走鸟蛋的肥猪们,鸟儿以自己的身体为武器,仿佛炮弹一样去攻击肥猪们的堡垒。为了简化问题,我们假设肥猪的城堡是范围为 N
2011-05-16 19:57:00
151
原创 数构作业-rp问题(树状数组)
2011-05-14 10:44:43#include#include#include#define N 100010using namespace std;struct Person{ int id, rp;}pe[N];int n,c[N],pa[N],pb[N];int cmp(Person a,Person b){ return a.rp>b.rp||(a.rp==b.rp&&a.id>b.id);}void update(int
2011-05-14 10:44:00
131
原创 HOJ 1166 敌兵布阵(树状数组、线段树)
<br />2011-05-13 22:02:17<br />题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1166<br />树状数组:http://baike.baidu.com/view/1420784.htm<br /> <br />#include<stdio.h>#define N 50005int a[N],n;void Add(int i,int j){ while (i<=n) { a
2011-05-13 22:04:00
140
原创 ZOJ 2855 Google Map
<br />2011-05-09 00:19:38<br />#include<stdio.h>#include<math.h>int main(){ const double PI = acos(-1); const double T = log(tan(PI/4+(85.0*PI/180)/2)); const double S = log(tan(PI/4+(-85.0*PI/180)/2)); const double W = -PI;
2011-05-09 00:19:00
272
原创 数构作业-LinkCity
<br />2011-05-09 00:08:58 <br />非常挫的代码·······最小生成树<br />#include<iostream>using namespace std;inline int abs(int x){ return x>0?x:-x;}inline int max(int a,int b){ return a>b?a:b;}inline int min(int a,int b){ return a<b?a:b;}
2011-05-09 00:09:00
169
原创 FOJ Problem 1022 三色二叉树
<br />2011-04-26 20:18:19 <br />题目地址:http://acm.fzu.edu.cn/problem.php?pid=1022<br />#include<iostream>#include<stack>#include<string>#define N 10010using namespace std;struct Node{ int lChild; int rChild;}nodes[N];int dp[N][2],dp
2011-04-26 20:19:00
375
原创 FOJ Problem 1304 Recaman's Sequence
<br />2011-04-25 23:37:12<br />题目地址:http://acm.fzu.edu.cn/problem.php?pid=1304<br />#include<iostream>#define N 500001#define M 3012505using namespace std;int t,i,j,k,dp[N],mark[M];int main(){ int index=0,max=0; dp[0]=0; for(i=0;i<M;i
2011-04-25 23:37:00
238
原创 FOJ Problem 1551 猪猪玩牌
<br />2011-04-24 20:34:58<br />题目地址:http://acm.fzu.edu.cn/problem.php?pid=1551<br />虽说是简单题,但刚开始还是不知道从何下手,很快的就百度之,看了人家的解题报告!也不知道是不是自己的出来的思路,因为看人家的报告没怎么理解,突然,灵感来了~~~碼碼碼碼碼碼……WA,看看看看,原来有一处碼错了,改之,AC……<br />思路:求出平均数,从数组第一个数开始,用s来表示第一个数与平均数的差,如果s!=0,则需要移动一次(co
2011-04-24 20:44:00
168
原创 FOJ Problem 1707 等式数量
<br />2011-04-24 09:15:20<br />题目地址:http://acm.fzu.edu.cn/problem.php?pid=1707<br /> 噩梦,难怪这题的AC率那么低,看似简单,陷阱重重,刚开始的思路是先确定a,b然后用二分法查找c,结果TEL<br />,看了网上人家的代码后,以为懂了,可是当按照自己以为正确的思路做出来后,却发现还是错了,原来是没考虑到该集合里面还有负数,所以我以为正确的思路错了~~~~<br />#include<iostream>#
2011-04-24 09:27:00
199
原创 FOJ 1081 Problem 1081 等分液体(BFS)
2011-04-23 10:44:37题目地址:http://acm.fzu.edu.cn/problem.php?pid=1081╮(╯▽╰)╭多谢Ocean 指点,不然怎么也想不到这一题是要用BFS来做的哇!!!代码有点长,,,,,,,#include#include#includeusing namespace std;struct S{ int l,m,n;}temp,temp2;int flag[151][151][151];// 用来标记状态int te
2011-04-23 10:47:00
430
1
原创 我的TOP排序造树
<br />2011-04-22 21:25:55<br />#include<iostream>#include<stack>#include<string>#define N 10010using namespace std;struct Node{ int color; Node* lChild; Node* rChild;}nodes[N],*head,*temp;void creatTree(char *str){ int i,j; st
2011-04-22 21:25:00
124
原创 数构作业-不同的数
2011-04-22 19:03:01700ms过了数构,过不了FOJ!!!!#include#include#define N 100010using namespace std;struct Node { int value; int index;}a[N];int b[N],c[N];int cmp(Node a,Node b){ return a.value
2011-04-22 19:03:00
152
原创 数构作业-game(MergeSort)
<br />2011-04-21 22:00:06<br />#include<iostream>using namespace std;int a[2]={0,0},b[100000],c[100000];void merge(int *p1,int *p2,int s,int t,int u){ int x=s,y,k=s,mid=(s+t)/2,c=0; y=mid+1; while (x<=mid&&y<=t) { if(p1[x]>p1[y]) {
2011-04-21 22:00:00
120
原创 FOJ Problem 1759 Super A^B mod C
<br />2011-04-20 20:04:55<br />题目地址:http://acm.fzu.edu.cn/problem.php?pid=1759<br />公式:A^B mod C = A^(B%euler(C))+euler(C)) mod C<br />证明:http://hi.baidu.com/aekdycoin/blog/item/b6f1762565bb403fc8955908.html<br /> <br />#include<iostream>#include<cmath
2011-04-20 20:14:00
328
原创 FOJ 1011 Problem 1684 迷宫救美(广搜+内功)
<br />2011-04-19 21:25:11<br />题目地址:http://acm.fzu.edu.cn/problem.php?pid=1684<br /> 假设楚留香走到map[i][j]点时所剩下的内功为e[i][j],当下一次在从不同路径走到该点时,如果所剩内功大于e[i][j],可以把该路径加入队列中,如果小于或等于,则不加入队列!(第一次做,没有考虑这一点,MLE了!!!!!)<br /> 题目说了楚留香消耗的内功为当前一步的墙的高度与其下一步的墙的高度的绝对差,
2011-04-19 21:35:00
186
原创 数构作业-survive (队列,广度搜索)
<br />2011-04-19 19:17:20<br />#include<iostream>#include<queue>using namespace std;struct Point { int x,y;}temp1,temp2;int a[][2]={{1,0},{-1,0},{0,1},{0,-1}};int main(){ char cmap[202][202]; int map[202][202],i,j,m,n,x,y,s; queue<P
2011-04-19 19:17:00
130
原创 FOJ Problem 1402 猪的安家
<br /> <br /> <br /> <br /> <br /> <br />2011-04-12 19:27:34<br />题目地址:http://acm.fzu.edu.cn/problem.php?pid=1402<br />中国剩余定理<br /> <br /> <br />#include<stdio.h>int main(){ __int64 A,An,result; int a[10],b[10],i,j,n; while (~scanf("%d",&n)) {
2011-04-12 19:28:00
407
原创 求N的阶乘的位数(大整数)
<br />2011-04-11 20:48:22<br />朴素公式为:<br /> log10(n!)=log10(1*2*3…*n)=log10(1)+log10(2)+…+log10(n)<br />求位数:log10(n!)=log10(1*2*3…*n)=log10(1)+log10(2)+…+log10(n),对log10(n!)的值取整加1就是n!的位数。<br />《计算机程序设计艺术》中给出了另一个公式<br /> n! = sqrt(2*π*n) * ((n/e)^n) *
2011-04-11 20:50:00
2937
原创 FOJ Problem 1016 无归之室
<br />2011-04-11 20:45:18<br />题目地址:http://acm.fzu.edu.cn/problem.php?pid=1016<br />迷迷糊糊地搞出来了,但方法的正确性能没有完全搞懂,O(∩_∩)O哈哈~<br />当小矩形的四个顶点都在大矩形的边上时,小矩形的长和宽(x和y)与大矩形的长和宽(a和b)满足下列方程:<br />x*cos(a)+y*sin(a)=a …(1)<br /> x*sin(a)+y*cos(a)=b …(2)<br />(
2011-04-11 20:46:00
423
原创 FOJ Problem 1012 Relatives
<br />2011-04-06 18:38:24<br />题目地址:http://acm.fzu.edu.cn/problem.php?pid=1012<br />思路:欧拉定理:http://blog.csdn.net/linbbq/archive/2011/04/06/6303731.aspx<br />#include<iostream>#include<cmath>using namespace std;int main(){ int n,i,nn,m,euler; wh
2011-04-06 18:45:00
321
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人