11 2013 档案
摘要:http://codeforces.com/problemset/problem/368/BB. Sereja and Suffixestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. S
阅读全文
摘要:http://poj.org/problem?id=3191题意:将一个整型的十进制整数转化为-2进制整数。 1 #include 2 #include 3 #include 4 #include 5 #define LL long long 6 using namespace std; 7 int main() 8 { 9 LL n,s[1010];10 while(~scanf("%lld",&n))11 {12 memset(s,0,sizeof(s));13 if (n==0)14 {15 ...
阅读全文
摘要:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2493 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn=1010; 6 const int maxm=maxn*maxn; 7 const long long INF=1LLq;31 q.push(s);32 vis[s] = 1;33 dis[s] = 0;34 while(!q.empty())35 {36...
阅读全文
摘要:http://poj.org/problem?id=1201题意:给定n个整数闭区间[a,b]和n个整数c,求一个最小的整数集合Z,满足Z里边的数中范围在闭区间[a,b]的个数不小于c个。思路:根据题目描述,可建模成一个差分约束系统。设S[i]表示小于等于i的整数的个数,R表示最大的右端点值,L表示最小的左端点值:则 S[b] - S[a-1] >= c;转化成:S[a-1] - S[b] = 0;转化成:S[i-1] - S[i] = M,即 S[L-1] - S[R] 2 #include 3 const int N=50005; 4 const int INF=1 dis[u]+e
阅读全文
摘要:http://poj.org/problem?id=1364题意:输入i,n,gt(lt),k; 判断是否存在这样一个序列,从第 i 项加到第 n+i 项的和 (gt) k.思路: 由题意知gt: Sn+i - Si > k;.......(1)lt: Si - Sn+i 建图。 1 #include 2 #include 3 const int N=120; 4 const int INF=1 dis[u]+edge[j].w)//更新各点到源点的距离30 dis[v] = dis[u]+edge[j].w;31 }32 }33 ...
阅读全文
摘要:http://poj.org/problem?id=3159思路:用O(V+ElogV)的Dijkstra算法求1到n的最短路。即用优先队列优化Dijkstra算法。 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn=300005; 6 const int maxm=150002; 7 struct node 8 { 9 int u,v,w;10 int next;11 } edge[maxm];12 struct pot13 {14 int v,w;15 p...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1025题意:富人路与穷人路都分别有从1到n的n个点,现在要在富人点与穷人点之间修路,但是要求路不能交叉,问最多能修多少条。思路:穷人路是按顺序给的,故求富人路的最长上升子序列即可。由于数据范围太大,应该用O(nlogn)的算法求LIS。 1 #include 2 #include 3 #include 4 using namespace std; 5 const int N=500005; 6 int r[N],d[N]; 7 int main() 8 { 9 int n,cnt = 0,x,y...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1429 1 #include 2 #include 3 #include 4 using namespace std; 5 struct node 6 { 7 int x,y; 8 int state; 9 int step; 10 } s,t; 11 int Time,n,m; 12 int s_x,s_y,e_x,e_y; 13 char a[32][32]; 14 int vis[32][32][1026];//标记状态 15 int dir[4][2] ...
阅读全文
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1506题意:给出n个矩形的高度,每个矩形的宽都为1,求相邻的矩形能组合成的最大的矩形的面积。思路:求出比第i个矩形大的最左边的矩形的位置 l[i], 及比第i个矩形大的最右边的矩形的位置 r[i], 则第i个矩形的面积 s = (r[i]-l[i]+1)*hign[i]。 如果第i-1个矩形比第i个矩形大,则 l[i] 必定在 l[i-1]的 左边,同理,r[i]必定在 r[i+1]的右边。 1 #include 2 #include 3 #include 4 #define LL __int64 5 ...
阅读全文
摘要:http://poj.org/problem?id=1584题意:判断所给的点能不能形成凸包,并判断所给的圆是否在凸包内。改了好几天的一个题,今天才发现是输入顺序弄错了,办过的最脑残的事情。。sad 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const int N=1002; 8 const double eps=1e-8; 9 double pi=acos(-1.0); 10 int n; 11 struct point 12 { 13 d...
阅读全文
摘要:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=35800#problem/D 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 const int INF=1p[N]; 14 mapname_id; 15 mappos_id; 16 int value[N],link[N][N],ans; 17 18 int res() 19 { 20 i...
阅读全文

浙公网安备 33010602011771号