05 2012 档案

 
HDU 1563 Find your present!
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1563找只出现一次的数,排个序处理下就行View Code #include <iostream>#include <algorithm>using namespace std ;int main(){ int n; while(scanf("%d",&n),n) { int a[201]; a[1]=a[n+1]=-1; for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(... 阅读全文
posted @ 2012-05-31 23:51 LegendaryAC 阅读(199) 评论(0) 推荐(0)
HDU 1124 Factorial
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1124求n!末尾有多少个0,2*5出0,所以既求有多少个因子5View Code #include <iostream>using namespace std ;int main(){ int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int ans=0; while(n) { n/=5; ans+=n; ... 阅读全文
posted @ 2012-05-31 16:05 LegendaryAC 阅读(115) 评论(0) 推荐(0)
HDU 3279 Nth Largest Value
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3279无聊题。。。View Code #include <iostream>#include <algorithm>using namespace std ;int main(){ int p; scanf("%d",&p); while(p--) { int cas; scanf("%d",&cas); int a[10]; for(int i=0;i<10;i++) scanf("%d",&a 阅读全文
posted @ 2012-05-31 13:07 LegendaryAC 阅读(188) 评论(0) 推荐(0)
巨菜的HDOJ400题感言
摘要:起床交3道水题HDOJ总算是到400题了。 从我接触程序设计到现在大概是七个月吧。七个月做这么一点题,简直是弱爆了,而且其中大部分是水题,做完能让我产生巨大成就感的题目不多。参加过几次为数不多的比赛,全部是以被虐爆收场。 明确下来“我要在大学好好搞ACM”这个目标也就是大一下学期的事情,之前可能对这个概念还很模糊吧,对刷题和学算法的热情不甚高涨,浪费了很多时间(大概能有两个多月无所事事?),不过既然决定了,那就向前看。转到计算机的专业是不太现实了,大学四年就在一个和计算机无关的专业混吧,毕竟每个人都有自己不同的活法。 比较神奇的事情是我在BISTU的oj上居然排到了第三,看来刷到第一... 阅读全文
posted @ 2012-05-31 13:00 LegendaryAC 阅读(157) 评论(0) 推荐(0)
HDU 2304 Electrical Outlets
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2304一个插头,n个插线板,问最后剩几个能插的电器的View Code #include <iostream>using namespace std ;int main(){ int n; scanf("%d",&n); while(n--) { int k; scanf("%d",&k); int s=0; for(int i=0;i<k;i++) { int w; sc... 阅读全文
posted @ 2012-05-31 12:39 LegendaryAC 阅读(201) 评论(0) 推荐(0)
HDU 2715 Herd Sums
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2715直接暴了。。。View Code #include <iostream>using namespace std ;int main(){ int n; while(~scanf("%d",&n)) { int ans=0,sum; for(int i=1;i<=n;i++) { sum=0; for(int j=i;j<=n;j++) { sum+=... 阅读全文
posted @ 2012-05-31 12:05 LegendaryAC 阅读(208) 评论(0) 推荐(0)
HDU 2716 Message Decowding
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2716水题View Code #include <iostream>using namespace std ;int main(){ char key[27],mes[81] ; while(~scanf("%s%*c",key)) { gets(mes) ; for(int i=0;mes[i];i++) { if(mes[i]>='A'&&mes[i]<='Z') putchar(key[mes... 阅读全文
posted @ 2012-05-31 11:22 LegendaryAC 阅读(149) 评论(0) 推荐(0)
HDU 2648 Shopping
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2648stl的map直接建立映射View Code #include <iostream>#include <algorithm>#include <string>#include <map>using namespace std ;string name[10001];int main(){ int n; while(~scanf("%d",&n)) { for(int i=0;i<n;i++) cin >> na 阅读全文
posted @ 2012-05-31 00:38 LegendaryAC 阅读(357) 评论(0) 推荐(0)
HDU 3336 Count the string
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3336求字符串的前缀在字符串中一共出现多少次。这个讲解的很清楚,传送门:http://972169909-qq-com.iteye.com/blog/1114968我用的思想是递推,把next数组向右平移一位,转移... 阅读全文
posted @ 2012-05-30 23:27 LegendaryAC 阅读(177) 评论(0) 推荐(0)
HDU 2800 Adding Edges
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2800View Code #include <iostream> using namespace std; int main(){ int n; while(scanf("%d",&n),n) printf("%d\n",(n+1)>>1); return 0;} 阅读全文
posted @ 2012-05-30 18:05 LegendaryAC 阅读(147) 评论(0) 推荐(0)
HDU 2594 Simpsons’ Hidden Talents
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2594好题,做完之后直接对KMP的理解提升一个档次。主要考察对_next数组含义的理解,之前的理解有点模糊,卡了两个半小时。View Code #include #include #include #include... 阅读全文
posted @ 2012-05-30 17:50 LegendaryAC 阅读(195) 评论(0) 推荐(0)
HDU 1686 Oulipo
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1686求子串个数,可重复,直接上KMP模板View Code #include #include using namespace std ; int n,m;char a[1000002],b[10002];int... 阅读全文
posted @ 2012-05-30 14:22 LegendaryAC 阅读(154) 评论(0) 推荐(0)
KMP
摘要:AB串下标都从1开始,kmp函数返回第一次成功匹配的A串下标,把其中注释去掉可以匹配多个Next[i]表示位置长度为1-i的字符串最多有长度为Next[i]的前缀等于其后缀char A[1000005],B[1000005] ;int Next[1000005],lenA,lenB ;void Ge... 阅读全文
posted @ 2012-05-30 13:59 LegendaryAC 阅读(184) 评论(0) 推荐(0)
HDU 1711 Number Sequence
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1711终于炼化了kmp算法,就算是现在我仍然惊异于字符串匹配居然存在线性时间的算法这种超出了我这种sb认知的东西。自己搞了N久,发现还是没有网上的模板写的好,这里直接收藏了。View Code #include #... 阅读全文
posted @ 2012-05-30 13:45 LegendaryAC 阅读(171) 评论(0) 推荐(0)
大家好,我是sb
摘要:大家好,我就是一个连搜索都学不会的sb。学了这么久连搜索是何物都不知道,BISTUACM已经不需要我了,哦也。 阅读全文
posted @ 2012-05-30 12:11 LegendaryAC 阅读(176) 评论(1) 推荐(0)
SRM 544 DIV 2 250
摘要:坑点:0特判View Code const double esp=1e-11;string ElectionFraudDiv2::IsFraudulent(vector <int> percentages) { vector <double> sb ; double sum=0; for (int i = 0 ; i < percentages.size() ; i++) { sum+=percentages[i]+0.0; sb.push_back(percentages[i]+0.0); } double sum1,sum2;... 阅读全文
posted @ 2012-05-29 23:56 LegendaryAC 阅读(181) 评论(0) 推荐(0)
LIS
摘要:O(nlog(n))的算法,网上讲解有很多,我就不在这里献丑了,直接上模板该模板计算从1到n的LIS,p[]为存放数列的数组最长上升子序列View Code int LIS(int n){ int l,r,m,i,tail = 0; for ( dp[ ++ tail ] = p[ 1 ... 阅读全文
posted @ 2012-05-29 12:28 LegendaryAC 阅读(364) 评论(0) 推荐(0)
输入挂
摘要:今天起决定总结自己做题写出来的遇到的找到的各种模板,先从输入挂开始啦有的题目需要大规模输入,很多情况用cin超时,用scanf就能过,因为scanf的速度远远快于cin。但是比scanf还要nb的输入是getchar(),这个读入速度极快,输入挂就是基于这点写的。整数View Code inline bool scan_d(int &num) { char in;bool IsN=false; in=getchar(); if(in==EOF) return false; while(in!='-'&&(in<'0'||in> 阅读全文
posted @ 2012-05-29 12:22 LegendaryAC 阅读(2880) 评论(0) 推荐(0)
HDU 1677 Nested Dolls
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1677这道题纠结了N个小时,因为原来找的模板里少了两个等号。。。结果就是错在了我一直觉得不会错的LIS里,让我认清了上升和非降的区别?下降数列的个数等于LIS,和导弹拦截那道题基本一致ps:连着三道LIS看排名都进了前三,好开心~View Code #include <iostream>#include <algorithm>using namespace std ;int dp[10001],p[20001];typedef struct L{ int w,h;}L;L kk[200 阅读全文
posted @ 2012-05-29 12:07 LegendaryAC 阅读(460) 评论(0) 推荐(0)
HDU 1950 Bridging signals
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1950和上一题基本一样,二分dp求LISps:排名居然刷到第一了,原来从来没有遇到呢,好开心~View Code #include <iostream>using namespace std ;int dp[10001],p[40001];int LIS(int n){ int l,r,m,i,tail = 0; for ( dp[ ++ tail ] = p[ 1 ],i = 2 ; i <= n ; ++ i ) { if ( dp[ tail ] <= p[ i ] )... 阅读全文
posted @ 2012-05-28 21:37 LegendaryAC 阅读(193) 评论(0) 推荐(0)
HDU 1025 Constructing Roads In JGShining's Kingdom
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1025题目有一定迷惑性,实际就是求LIS,我原来掌握的朴实的O(n^2)算法果断超时,新学了一种二分dp O(nlog(n))的算法,直接上模板了,还要多多体会啊View Code #include <iostream>using namespace std ;int dp[10001],p[50001];int LIS(int n){ int l,r,m,i,tail = 0; for ( dp[ ++ tail ] = p[ 1 ],i = 2 ; i <= n ; ++ i ) { . 阅读全文
posted @ 2012-05-28 21:29 LegendaryAC 阅读(119) 评论(0) 推荐(0)
HDU 1316 How Many Fibs?
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1316大数,斐波那契数列View Code import java.io.*;import java.math.*;import java.util.*;import java.text.*;public class Main{ public static void main(String[]args) { Scanner cin=new Scanner (new BufferedInputStream(System.in)); BigInteger a,b; ... 阅读全文
posted @ 2012-05-28 15:45 LegendaryAC 阅读(182) 评论(0) 推荐(0)
HDU 1394 Minimum Inversion Number
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1394求最小逆序数,逆序数的树状数组求法昨天学会了,今天这题开始用个无脑O(n*n*log(n))的方法,果断超时。其实逆序数只用求一边,每移动一次数列,逆序数增加num[i]-1个,对应减少n-num[i]个,递推即可。View Code #include <stdio.h>#include <stdlib.h> #include <string.h>int n;int tree[5001],num[5001];int lowbit(int i){ return i&am 阅读全文
posted @ 2012-05-28 15:00 LegendaryAC 阅读(156) 评论(0) 推荐(0)
HDU 1016 Prime Ring Problem
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1016经典问题,素数环。直接回溯即可。View Code #include <stdio.h>#include <string.h>int n;int a[30];int prime[100],vis[30];void dfs(int cur){ if(cur==n && prime[a[0]+a[n-1]]==0) { printf("%d",a[0]); for(int i=1;i<n;i++) printf(" %d" 阅读全文
posted @ 2012-05-28 12:37 LegendaryAC 阅读(161) 评论(0) 推荐(0)
HDU 2689 Sort it
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2689树状数组求逆序数,原来一直没搞明白,今天看了一遍文章讲的很清楚,下面把有关内容粘过来:对于小数据,可以直接插入树状数组,对于大数据,则需要离散化,所谓离散化,就是将100 200 300 400 500 ---> 1 2 3 4 5这里主要利用树状数组解决计数问题。首先按顺序把序列a[i]每个数插入到树状数组中,插入的内容是1,表示放了一个数到树状数组中。然后使用sum操作获取当前比a[i]小的数,那么当前i - sum则表示当前比a[i]大的数,如此反复直到所有数都统计完,比如4 3 1 2 i 阅读全文
posted @ 2012-05-28 01:24 LegendaryAC 阅读(472) 评论(0) 推荐(0)
HDU 2154 跳舞毯
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2154无聊题。。。View Code #include <stdio.h>#include <stdlib.h> #include <string.h>const int mod=10000;int a[1001],b[1001],c[1001];int main(){ int n; while(scanf("%d",&n),n) { a[0]=1;b[0]=c[0]=0; for(int i=1;i<=n;i++) { a[i... 阅读全文
posted @ 2012-05-28 00:50 LegendaryAC 阅读(247) 评论(0) 推荐(0)
HDU 1203 I NEED A OFFER!
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=120301背包ps:做01背包经常不注意数组的大小,这题数组开小了又是各种waView Code #include <iostream>using namespace std ;double f[10001],w[1001];int c[1001];int main(){ int n,m; while(scanf("%d%d",&n,&m)) { if(n==0&&m==0)break; for(int i=1;i<=m;i++) scan 阅读全文
posted @ 2012-05-27 23:16 LegendaryAC 阅读(143) 评论(0) 推荐(0)
HDU 2546 饭卡
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=254601背包,开始内层循环写成v>=0无限wa。。。一定要注意数组越界的问题、、、View Code #include <iostream>using namespace std ;int main(){ int n; while(scanf("%d",&n),n) { int w[1010]; int maxx=0; int flag; for(int i=1;i<=n;i++) { scanf(... 阅读全文
posted @ 2012-05-27 22:38 LegendaryAC 阅读(193) 评论(0) 推荐(0)
HDU 1009 FatMouse' Trade
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1009无聊的贪心View Code #include <stdio.h>#include <stdlib.h>typedef struct L{ int j,k; double w;}L;L kk[1001];int cmp(const void*a,const void*b){ L*c=(L*)a; L*d=(L*)b; return d->w > c->w ? 1 : -1 ;}int main(){ int m,n; while(scanf("%d%d 阅读全文
posted @ 2012-05-27 16:45 LegendaryAC 阅读(124) 评论(0) 推荐(0)
HDU 2539 点球大战
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2539无聊题,可能会有人名开头小写的数据,所以一定要倒着找no,我这种写法是中间出了点故障,导致写的很麻烦,不足取View Code #include <iostream>#include <string>using namespace std ;int main(){ int n; while(scanf("%d%*c",&n),n) { int flag1[10],flag2[10]; char str[101]; int ans1=0,ans2... 阅读全文
posted @ 2012-05-27 16:17 LegendaryAC 阅读(285) 评论(0) 推荐(0)
HDU 1982 Kaitou Kid - The Phantom Thief (1)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1982字符串处理View Code #include <iostream>#include <string>using namespace std ;char str[27]={"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};int main(){ int t; scanf("%d%*c",&t); while(t--) { string s; cin >> s ; for(int i=0;i<s.lengt 阅读全文
posted @ 2012-05-27 10:04 LegendaryAC 阅读(189) 评论(0) 推荐(0)
HDU 1976 Software Version
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1976水题View Code #include <stdio.h>#include <string.h>int main(){ int t; int a1,a2,a3; int b1,b2,b3; scanf("%d",&t); while(t--) { scanf("%d%d%d",&a1,&a2,&a3); scanf("%d%d%d",&b1,&b2,&b3); i 阅读全文
posted @ 2012-05-26 22:49 LegendaryAC 阅读(169) 评论(0) 推荐(0)
HDU 1977 Consecutive sum II
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1977很容易看出规律View Code #include <stdio.h>#include <string.h>int main(){ int t; __int64 n; scanf("%d",&t); while(t--) { scanf("%I64d",&n); printf("%I64d %I64d\n",n*n*n,(n+1)*(n+1)*(n+1)); } return 0;} 阅读全文
posted @ 2012-05-26 21:00 LegendaryAC 阅读(121) 评论(0) 推荐(0)
HDU 3792 Twin Prime Conjecture
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3792n为负数,静态查询,用树状数组写,蛋疼可见一斑。打素数表的时候内层循环对i再加一个判断,是为了防止i*j因为溢出而恒真(引用自sx老祖)View Code #include <iostream>using namespace std ;const int MAX=100001;int prime[MAX],tree[MAX],num[MAX];int lowbit(int i){ return i&(-i);} void update(int x,int val){ for(int 阅读全文
posted @ 2012-05-25 14:37 LegendaryAC 阅读(316) 评论(0) 推荐(0)
HDU 2368 Alfredo's Pizza Restaurant
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2368初中数学题,圆幂定理View Code #include <iostream>using namespace std ;int main(){ double r,w,l; int nCase=1; while(scanf("%lf",&r),r) { scanf("%lf%lf",&w,&l); if(r*r-(w/2)*(w/2)<(l/2)*(l/2)) printf("Pizza %d does not f 阅读全文
posted @ 2012-05-25 12:55 LegendaryAC 阅读(168) 评论(0) 推荐(0)
HDU 1984 Mispelling4
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1984字符串处理View Code #include <iostream>#include <string>using namespace std;int main(){ int t,n; char str[110]; scanf("%d",&t); for(int cas=1;cas<=t;cas++) { scanf("%d %s",&n,str); str[n-1]='\0'; printf(" 阅读全文
posted @ 2012-05-25 06:22 LegendaryAC 阅读(163) 评论(0) 推荐(0)
HDU 1996 汉诺塔VI
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1996递推View Code #include <iostream>#include <string>using namespace std;int main(){ int t; __int64 dp[30]={0,3}; for(int i=2;i<30;i++) dp[i]=dp[i-1]*3; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); printf(&quo 阅读全文
posted @ 2012-05-25 05:26 LegendaryAC 阅读(205) 评论(0) 推荐(0)
HDU 1985 Conversions
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1985小学计算题View Code #include <iostream>#include <string>using namespace std;int main(){ int t; scanf("%d",&t); for(int cas=1;cas<=t;cas++) { double n; string d; cin >> n >> d; if(d=="kg") printf("%d %.4l 阅读全文
posted @ 2012-05-25 05:08 LegendaryAC 阅读(227) 评论(0) 推荐(0)
HDU 2393 Higher Math
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2393判断直角三角形View Code #include <stdio.h>#include <string.h>int main(){ int t; scanf("%d",&t); for(int cas=1;cas<=t;cas++) { int a,b,c; scanf("%d%d%d",&a,&b,&c); printf("Scenario #%d:\n",cas); if(a*a 阅读全文
posted @ 2012-05-25 04:31 LegendaryAC 阅读(214) 评论(0) 推荐(0)
HDU 2391 Filthy Rich
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2391一路逆着推过去View Code #include <stdio.h>#include <string.h>const int INF=100000000;int map[1001][1001],dp[1001][1001];int Max(int a,int b,int c){ int max=-INF; if(a>max)max=a; if(b>max)max=b; if(c>max)max=c; return max;}int main(){ int t. 阅读全文
posted @ 2012-05-25 04:04 LegendaryAC 阅读(217) 评论(0) 推荐(0)
HDU 1708 Fibonacci String
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1708不能直接用string加,最后的位数很多,会超内存。一定注意特殊处理k=0和k=1的情况。最后有空行View Code #include <iostream>#include <cstdlib>#include <cstring>#include <string>#include <stack>#include <queue>#include <map>#include <algorithm>using na 阅读全文
posted @ 2012-05-25 03:52 LegendaryAC 阅读(172) 评论(0) 推荐(0)
HDU 3501 Calculation 2
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3501继续欧拉函数,关键点是求小于n且与n互质的数的和。公式是Eular(n)*n/2,简略证明如下:原问题等价于一个数n,如果a与它互质,那么n-a也与它互质;反证法,假设n与a互质,n与n-a不互质设n和n-a的最大公约数为m,则n=p*m,n-a=q*m所以a=(p-q)*m,推导出a和n有公约数m,与假设矛盾View Code #include <iostream>#include <cstdlib>#include <cstring>#include <st 阅读全文
posted @ 2012-05-25 02:00 LegendaryAC 阅读(128) 评论(0) 推荐(0)
HDU 1787 GCD Again
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1787依然是欧拉函数的模板题,求有多少个小于等于N且不与N互质的数,减去N本身再减去和N互质的就好了,小于N且和N互质的数的个数就用欧拉函数算了View Code #include <iostream>#include <cstdlib>#include <cstring>#include <string>#include <stack>#include <queue>#include <map>#include <al 阅读全文
posted @ 2012-05-25 00:48 LegendaryAC 阅读(166) 评论(0) 推荐(0)
HDU 2824 The Euler function
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2824同上一题,裸欧拉函数View Code #include <iostream>#include <cstdlib>#include <cstring>#include <string>#include <stack>#include <queue>#include <map>#include <algorithm>using namespace std;const int MAX=3000001;int ph 阅读全文
posted @ 2012-05-25 00:09 LegendaryAC 阅读(163) 评论(0) 推荐(0)
HDU 1286 找新朋友
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1286裸欧拉函数,欧拉函数是求比n小的数中有多少个与n互质View Code #include <iostream>#include <cstdlib>#include <cstring>#include <string>#include <stack>#include <queue>#include <map>#include <algorithm>using namespace std;const int MA 阅读全文
posted @ 2012-05-25 00:04 LegendaryAC 阅读(293) 评论(0) 推荐(0)
HDU 4163 Stock Prices
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4163稳定排序View Code #include <iostream>#include <cstdlib>#include <cstring>#include <string>#include <stack>#include <queue>#include <map>using namespace std;typedef struct L{ int price; int idx;}L;L kk[1000001];int cm 阅读全文
posted @ 2012-05-24 23:19 LegendaryAC 阅读(208) 评论(0) 推荐(0)
HDU 1872 稳定排序
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1872稳定排序,用一个变量idx记录位置保持稳定View Code #include <iostream>#include <cstdlib>#include <cstring>#include <string>#include <stack>#include <queue>#include <map>using namespace std;typedef struct L{ char name[51]; int score; 阅读全文
posted @ 2012-05-24 22:04 LegendaryAC 阅读(252) 评论(0) 推荐(0)
HDU 1022 Train Problem I
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1022STL中栈的应用练习,数组要开够啊。。。无语View Code #include <iostream>#include <stack>using namespace std;int main(){ stack <char> s; char in[11],out[11]; int n; bool flag[30]; while(~scanf("%d%s%s",&n,in,out)) { int i,j,cnt; i=j=cnt=0; ... 阅读全文
posted @ 2012-05-24 16:30 LegendaryAC 阅读(146) 评论(0) 推荐(0)
HDU 1273 漫步森林
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1273乱搞题,n-1减去起点,把剩下的点分成尽可能相等的两部分1、2(为了得到尽可能大的答案),对于1内部来讲,显然总能保证“新鲜”,在新鲜1后,不难看出2的每个点都对应着一个“新鲜”说的乱七八糟,大概就这样吧。。。View Code #include <iostream>#include <queue>#include <stack>#include <vector>using namespace std;int main(){ int n; while(sc 阅读全文
posted @ 2012-05-24 13:46 LegendaryAC 阅读(245) 评论(0) 推荐(0)
HDU 3584 Cube
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3584裸三维树状数组。。。除了三维的容斥要稍微想一下别的都和一维、二维的一样了View Code #include <iostream>using namespace std;const int MAX=101;int n;int tree[MAX][MAX][MAX];int lowbit(int i){ return i&(-i);}void update(int x,int y,int z){ for(int i=x;i<=n;i+=lowbit(i)) for(int j=y 阅读全文
posted @ 2012-05-23 19:11 LegendaryAC 阅读(139) 评论(0) 推荐(0)
HDU 2642 Stars
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2642裸二维树状数组,没有秒杀,坑点是这题的询问是x1,x2,y1,y2(其实题目说得清清楚楚,惯性思维害死人?写完不过sample无力吐槽)。然后犯了一个巨2的笔误,死活没查出来,还是让路人王同学看出来的、、、、跪了View Code #include <iostream>using namespace std;const int MAX=1010;int vis[MAX][MAX],tree[MAX][MAX];int lowbit(int i){ return i&(-i);}voi 阅读全文
posted @ 2012-05-23 13:12 LegendaryAC 阅读(259) 评论(0) 推荐(0)
HDU 1892 See you~
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1892二维树状数组,很裸。。。View Code #include <iostream>#include <algorithm> #include <cstring>using namespace std;const int MAX=1010;int weight[MAX][MAX],tree[MAX][MAX];int lowbit(int i){ return i&(-i);}void update(int x,int y,int val){ for(int i 阅读全文
posted @ 2012-05-22 21:40 LegendaryAC 阅读(134) 评论(0) 推荐(0)
HDU 1150 Machine Schedule
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1150二分图最大匹配,匈牙利算法View Code #include #include const int MAX1=101;const int MAX2=1001;int k,m,n;int match[MAX1... 阅读全文
posted @ 2012-05-21 17:55 LegendaryAC 阅读(137) 评论(0) 推荐(0)
HDU 1063 Exponentiation
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1063依然是高精度,和上一题很像,不过用上一题的方法一直超时?颇为费解。查了几个函数的用法,直接用函数操作就不超时了?这题mark一下以后还要再看,对超时表示不太理解。stripTrailingZeros()是去掉后缀0,toPlainString()是转成非指数型的字符串(上一题要知道这两个函数直接秒杀了哈。。。)。startsWith("//字符串1")判断给定字符串是否以字符串1开头(对应的还有endsWith())。substring()的用法参考百度百科,看一眼就明白了:&quo 阅读全文
posted @ 2012-05-21 11:38 LegendaryAC 阅读(141) 评论(0) 推荐(0)
HDU 1753 大明A+B
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1753在小数点存在的情况下去掉后面的0View Code import java.io.*;import java.math.*;import java.util.*;import java.text.*;public class Main{ public static void main(String[] args) { Scanner cin=new Scanner (new BufferedInputStream(System.in)); BigDecimal a... 阅读全文
posted @ 2012-05-21 10:38 LegendaryAC 阅读(152) 评论(0) 推荐(0)
HDU 1047 Integer Inquiry
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1047大数View Code import java.io.*;import java.math.*;import java.util.*;import java.text.*;public class Main{ public static void main(String[] args) { Scanner cin=new Scanner (new BufferedInputStream(System.in)); BigInteger sum,a; i... 阅读全文
posted @ 2012-05-21 10:09 LegendaryAC 阅读(113) 评论(0) 推荐(0)
HDU 1134 Game of Connections
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1134在上一题的基础上加个-1跳出的判断、、、View Code import java.io.*;import java.math.*;import java.util.*;import java.text.*;public class Main{ public static void main(String[] args) { Scanner cin=new Scanner (new BufferedInputStream(System.in)); BigInteg... 阅读全文
posted @ 2012-05-20 23:53 LegendaryAC 阅读(198) 评论(0) 推荐(0)
HDU 1130 How Many Trees?
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1130和上一题一模一样View Code import java.io.*;import java.math.*;import java.util.*;import java.text.*;public class Main{ public static void main(String[] args) { Scanner cin=new Scanner (new BufferedInputStream(System.in)); BigInteger[] f=new B... 阅读全文
posted @ 2012-05-20 23:43 LegendaryAC 阅读(327) 评论(0) 推荐(0)
HDU 1023 Train Problem II
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1023卡特兰数,要注意是大数,直接学着用java搞大数了View Code import java.io.*;import java.math.*;import java.util.*;import java.text.*;public class Main{ public static void main(String[] args) { Scanner cin=new Scanner (new BufferedInputStream(System.in)); Big... 阅读全文
posted @ 2012-05-20 23:40 LegendaryAC 阅读(159) 评论(0) 推荐(0)
HDU 2063 过山车
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2063二分图最大匹配,参照白书上邻接表建的图View Code #include #include const int MAX1=501;const int MAX2=1001;int k,m,n;int matc... 阅读全文
posted @ 2012-05-20 15:56 LegendaryAC 阅读(116) 评论(0) 推荐(0)
HDU 2164 Rock, Paper, or Scissors?
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2164剪刀石头布,无脑模拟View Code #include <stdio.h>int gao(char p1,char p2){ if(p1=='S'&&p2=='P')return 1; if(p1=='P'&&p2=='R')return 1; if(p1=='R'&&p2=='S')return 1; if(p2=='S'& 阅读全文
posted @ 2012-05-20 14:01 LegendaryAC 阅读(189) 评论(0) 推荐(0)
HDU 1280 前m大的数
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1280hash+最大堆,STL堆View Code #include <iostream>#include <map>#include <vector>#include <queue>#include <cstring>using namespace std;int hash[10001];int main(){ int n,m; priority_queue <int> q; while(~scanf("%d%d", 阅读全文
posted @ 2012-05-19 23:28 LegendaryAC 阅读(321) 评论(0) 推荐(0)
HDU 1029 Ignatius and the Princess IV
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1029看题意就是建立一个映射,用map直接过View Code #include <iostream>#include <map>using namespace std;int main(){ int n; while(~scanf("%d",&n)) { map <int ,int > M; int bz=(n+1)/2; while(n--) { int a; scanf("%d",&a)... 阅读全文
posted @ 2012-05-19 19:08 LegendaryAC 阅读(241) 评论(0) 推荐(0)
HDU 1259 ZJUTACM
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1259水题View Code #include <stdio.h>#include <string.h>int main(){ int n,m,x,y,i,a[10]; scanf("%d",&n); while(n--) { memset(a,0,sizeof(a)); a[2]=1; scanf("%d",&m); while(m--) { scanf("%d%d",&x,&y); ... 阅读全文
posted @ 2012-05-14 20:32 LegendaryAC 阅读(180) 评论(0) 推荐(0)
HDU 2066 一个人的旅行
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2066裸最短路,一开始又sb了,处理错复杂度TLE,囧View Code #include #include const int INF=1000000001;const int maxn=1001;int G[m... 阅读全文
posted @ 2012-05-13 22:57 LegendaryAC 阅读(255) 评论(0) 推荐(0)
HDU 1596 find the safest road
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1596最短路ps:0可以理解为那两个城市之间没有直接的通道,少看了这个条件错惨,在sx和zbw两位祖先的帮助下认清了这个问题#include #include using namespace std;const d... 阅读全文
posted @ 2012-05-13 17:22 LegendaryAC 阅读(490) 评论(0) 推荐(0)
HDU 2112 HDU Today
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2112把地名和数字对应一下,就变成模板题了#include #include using namespace std;const int INF=10000000;const int maxn=101;int ni... 阅读全文
posted @ 2012-05-13 12:45 LegendaryAC 阅读(319) 评论(0) 推荐(0)
HDU 1874 畅通工程续
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1874第一次知道有个东西叫重边。。。囧View Code #include #include using namespace std;const int INF=1000000000;int map[210][21... 阅读全文
posted @ 2012-05-13 03:15 LegendaryAC 阅读(151) 评论(0) 推荐(0)
HDU 2544 最短路
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2544在TCO又一次0之后。。。突然会写最短路了,ORZView Code #include #include using namespace std;const int INF=100000000;int map... 阅读全文
posted @ 2012-05-13 02:59 LegendaryAC 阅读(169) 评论(0) 推荐(0)
HDU 1541 Stars
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1541画星星,注意要把所有点向右平移一位,否则update会死循环(在(0,0))ps:数组一定要开够啊啊啊View Code #include <stdio.h>#include <string.h>const int maxn1=15001;const int maxn2=32001;int n;int tree[maxn2],ans[maxn1];int lowbit(int i){ return i&(-i);}void update(int i,int val){ w 阅读全文
posted @ 2012-05-11 19:23 LegendaryAC 阅读(149) 评论(0) 推荐(0)
HDU 1678 Shopaholic
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1678继续是STL的堆,这道题最小堆最大堆均可,随手写一个就ok。刚开始题意理解有问题,各种wa,郁闷得要死。从最小堆来看,三个一组最小的加到答案里。如果元素总数不能被3整除,就先把堆顶元素出堆,直到能被3整除为止。View Code #include <iostream>#include <queue>#include <algorithm>using namespace std;int main(){ int t,n,p; int ans; priority_queue 阅读全文
posted @ 2012-05-11 12:06 LegendaryAC 阅读(230) 评论(0) 推荐(0)
HDU 4006 The kth great number
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4006第一反应是线段树,不过发现k是固定的。用STL的优先队列,很爽。http://blog.chinaunix.net/space.php?uid=533684&do=blog&cuid=2615612我从上面的博客学到很多STL优先队列的知识,ORZ一个View Code #include <iostream>#include <vector>#include <queue>using namespace std;int main(){ int n,k, 阅读全文
posted @ 2012-05-11 00:57 LegendaryAC 阅读(201) 评论(0) 推荐(0)
HDU 4079 Happy Telephones
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4079比大小的题。。。没用条件给一堆。。。View Code #include <iostream>#include <map>#include <string>#include <algorithm>using namespace std;typedef struct L{ int start,during;}L;L phone[11000];int main(){ int n,m,i,j; int start,during; int ans; while(s 阅读全文
posted @ 2012-05-10 18:05 LegendaryAC 阅读(251) 评论(0) 推荐(0)
HDU 1027 Ignatius and the Princess II
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1027求数列n的第m个排列,STL中next_permutation的应用。相对应的还有prev_permutation。View Code #include #include #include #include using namespace std;int main(){ int n,m,i; int s[1100]; while(~scanf("%d%d",&n,&m)) { for(i=1;iusing namespace std ;int n,m ;int vi. 阅读全文
posted @ 2012-05-10 17:08 LegendaryAC 阅读(195) 评论(0) 推荐(0)
HDU 1263 水果
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1263STL中map的练习View Code #include <iostream>#include <map>#include <string>using namespace std;int main(){ int n,m,k,i; int f=0; scanf("%d",&n); while(n--) { if(!f)f++; else putchar('\n'); map <string ,map<string, 阅读全文
posted @ 2012-05-10 16:35 LegendaryAC 阅读(259) 评论(0) 推荐(0)
HDU 1075 What Are You Talking About
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1075趁着HDOJ活了赶快交一个、、、刚开始学习STL的应用,这个代码学习自sx老祖。。。View Code #include <stdio.h> #include <iostream> #include <string> #include <map>using namespace std; int main(){ int i; char str[3001]; map <string,string> M; string str1,str2; cin 阅读全文
posted @ 2012-05-10 12:46 LegendaryAC 阅读(229) 评论(0) 推荐(0)
HDU 1671 Phone List
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1671依旧是Trie树,和上一题差不太多View Code #include #include #include const int MAX=10; typedef struct Trie{ Trie *... 阅读全文
posted @ 2012-05-09 02:14 LegendaryAC 阅读(214) 评论(0) 推荐(0)
HDU 1251 统计难题
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1251第一道Trie树,感觉有点厉害View Code #include #include #include const int MAX=26; typedef struct Trie{ Trie *ne... 阅读全文
posted @ 2012-05-09 01:53 LegendaryAC 阅读(297) 评论(0) 推荐(0)
HDU 1102 Constructing Roads
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1102最简单的最小生成树View Code #include #include #include int p[110];int cnt,n; typedef struct L{ int a,b,d; }L... 阅读全文
posted @ 2012-05-08 11:34 LegendaryAC 阅读(194) 评论(0) 推荐(0)
HDU 1162 Eddy's picture
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1162最简单的最小生成树。。。View Code #include #include #include int p[110];int cnt,n; typedef struct L{ int a,b; ... 阅读全文
posted @ 2012-05-07 23:37 LegendaryAC 阅读(185) 评论(0) 推荐(0)
HDU 1301 Jungle Roads
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1301最简单的最小生成树View Code #include #include int p[30];int cnt,n; typedef struct L{ int a,b,d;}L;L r[1000]; ... 阅读全文
posted @ 2012-05-07 22:43 LegendaryAC 阅读(179) 评论(0) 推荐(0)
HDU 1166 敌兵布阵(2)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1166老题新做,树状数组,比线段树省了300k内存View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>const int maxn=51000;int s[maxn];int nCase=1,n;int lowbit(int i){return i&(-i);} void update(int i,int val){ while(i<= 阅读全文
posted @ 2012-05-07 12:36 LegendaryAC 阅读(160) 评论(0) 推荐(0)
总结自己的近期表现
摘要:上学期接触c语言随便学了学,寒假忘了干啥,开学到现在一直在打酱油。综上,自己的近期表现就是没有表现,哦也! 阅读全文
posted @ 2012-05-04 15:45 LegendaryAC 阅读(209) 评论(0) 推荐(0)
教学:如何辨别狗和“畅畅”
摘要:众所周知,畅畅这种生物曾经都是以狗的面貌展现在大家眼前,这就给大家造成了一种“畅畅”是狗的幻觉。不过,如果您也这么想,那就大错特错了。不同点:1、交给狗的工作你可以放心,比如看家护院神马的。不过交给“畅畅”的事情永远不能放心,因为它一定会忘记。2、可以和狗约会,但千万不要和畅畅约会。“畅畅”在99%的情况下都会放你鸽子;如果不幸赶上那1%,您就不光是不爽了。“畅畅”对突发事件的处理能力基本为0,对于路线的选择一定会精心编程计算出最长路线,并会不时发出没有丝毫建设性消极情绪。3、周一到周五,狗不上课,而畅畅一定全天30h都在上课,纳尼?你说畅畅没在上课?哦了,那他一定在考试。4、周六周日,畅畅一 阅读全文
posted @ 2012-05-04 15:10 LegendaryAC 阅读(226) 评论(0) 推荐(0)
HDU 1992 Tiling a Grid With Dominoes
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1992hdu上很多这种砖块问题,废话少说,下面开始分析。高度是固定的,只用考虑宽度带来的影响。少一列,是dp[1]*dp[i-1]=dp[i-1]少两列,是dp[2]*dp[i-2]=5*dp[i-2],但是其中一种情况与少一列的重复,所以只有4*dp[i-2]再往后少奇数列,都只有2*dp[i](考虑可能情况并且不与前两种情况产生重复)再往后少偶数列,都只有3*dp[i](考虑可能情况并且不与前两种情况产生重复)综上分析,dp[i]=dp[i-1]+4*dp[i-2]+2*(dp[i-3]+dp[i-5]. 阅读全文
posted @ 2012-05-02 12:44 LegendaryAC 阅读(647) 评论(0) 推荐(0)
学不会
摘要:学不会线段树,怎么办???学的上火,怎么都不懂,不懂啊有木有!!说好的所有算法都接触一下呢,怎么上来就卡在线段树了??都有简单啊,有木有!!!我怎么就学不会捏!!!给人提鞋的好歹是个人吧,我就是一条狗啊!!!啊!哦!噢!嗷!哈!呼!真不要脸!这都有脸学下去!******************** 阅读全文
posted @ 2012-05-01 14:36 LegendaryAC 阅读(154) 评论(0) 推荐(0)
HDU 1060 Leftmost Digit
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1060脑筋急转弯。View Code #include <stdio.h>#include <math.h> int main(){ int t; double n; scanf("%d",&t); while(t--) { scanf("%lf",&n); printf("%d\n",(int)pow(10.0,n*log10(n)-(__int64)(n*log10(n)))); } return 0;} 阅读全文
posted @ 2012-05-01 14:25 LegendaryAC 阅读(126) 评论(0) 推荐(0)