
hdu
码农同学
爱动漫,爱AC,立志成为攻城师!
展开
-
杭电ACM 2054 A == B ?
http://acm.hdu.edu.cn/showproblem.php?pid=2054这道题费了我好长时间!变态!这道题目上没给具体的数值类型,所以要开一个很大的字符数组。要注意下面几种情况:1)前面的无效0去掉2)小数点后面的无效0去掉3)-0=04)可以去掉的话,最好去掉小数点,防止10==10.0这种情况发生#include #include u原创 2012-08-05 21:16:20 · 6900 阅读 · 0 评论 -
ACM/ICPC要求的知识点
排序算法(平方排序算法的应用,Shell排序,快速排序,归并排序,时间复杂度下界,三种线性时间排序,外部排序)数论(整除,集合论,关系,素数,进位制,辗转相除,扩展的辗转相除,同余运算,解线性同余方程,中国剩余定理)指针(链表,搜索判重,邻接表,开散列,二叉树的表示,多叉树的表示)按位运算(and,or,xor,shl,shr,一些应用)图论(图论模型的建立,平面图,欧拉公式与五色转载 2012-08-09 23:59:16 · 1265 阅读 · 0 评论 -
hdu 2096 小明A+B
http://acm.hdu.edu.cn/showproblem.php?pid=2096注意int型,a不超过int型所表示的最大整数,b也不超过,但是a+b可能超过!#include using namespace std;int main(){ int T; cin>>T; while(T--){ int a,b; cin>>a>>b; cout<<原创 2012-08-10 10:16:54 · 2027 阅读 · 0 评论 -
hdu 2089 不要62
http://acm.hdu.edu.cn/showproblem.php?pid=2089可能是大数据比较多,必须打表解决。最开始有个小错误,导致了WA,就是遍历的时候没遍历够。。。。1000000写成100000了,细心啊。#include using namespace std;bool bingo(int n){ while(n){ if(n%10==4||n%1原创 2012-08-11 10:58:51 · 1825 阅读 · 0 评论 -
hdu 2090 算菜价
http://acm.hdu.edu.cn/showproblem.php?pid=2090这道题真邪乎,编译错误好几次,杭电的编译器和我的不一样啊啊啊~~~~囧死了无语。。。。。看了别人的代码才AC的,破题#include int main(){ char s[100]; double n,price,sum=0.0; while(scanf("%s%lf%lf",s,&n原创 2012-08-11 11:22:23 · 3509 阅读 · 0 评论 -
hdu 1021 Fibonacci Again
http://acm.hdu.edu.cn/showproblem.php?pid=1021找规律,一次找出f[0]~f[n]的对三取余的数:1,2,0,2,2,1,0,1,1,2,0,2,2,1,0,1,1,2,0,2,2,1,0,1.........不断循环我们的目的是找到取余之后的0与n的关系,除了第一个,0和0之间都是有三个数,所以容易得到只要n%4==2,那么f[n]=0.原创 2012-08-11 17:03:28 · 818 阅读 · 0 评论 -
hdu 1004 Let the Balloon Rise
http://acm.hdu.edu.cn/showproblem.php?pid=1004枚举遍历,字符串排序。#include #include #include using namespace std;int main(){ int n; int col[1000]; string s[1010]; int flag; while(cin>>n&&n){原创 2012-08-11 17:41:39 · 756 阅读 · 0 评论 -
hdu 1231 最大连续子序列
http://acm.hdu.edu.cn/showproblem.php?pid=1231#include using namespace std;int a[10010];int main(){ int N; while(scanf("%d",&N)!=EOF&&N){ int i,j=0,sum=0,max=-1,s=0,e=N-1; for(i=0;原创 2012-08-07 23:19:43 · 704 阅读 · 0 评论 -
hdu 1003 Max Sum (最大连续子序列)
http://acm.hdu.edu.cn/showproblem.php?pid=1003动态规划。。。。。和第1231道题不同,这道题有负数!wa了n次。。。。。悲剧#include using namespace std;int a[100010];int main(){ int T; cin>>T; for(int c=1;c<=T;c++){ int原创 2012-08-07 23:54:59 · 815 阅读 · 0 评论 -
杭电ACM 1715 大菲波数
http://acm.hdu.edu.cn/showproblem.php?pid=1715大数相加算法解决!#include using namespace std;int f[1001][2010];int main(){ int Pi; int N; cin>>N; memset(f,0,sizeof(f)); f[1][0]=1; f[2][0]=1; fo原创 2012-08-09 20:59:58 · 2207 阅读 · 0 评论 -
杭电ACM 2098 分拆素数和
http://acm.hdu.edu.cn/showproblem.php?pid=2098注意两个数相等的情况要剔除!#include using namespace std;int Is_Prime(int a){ for(int i=2;i*i<=a;i++) if(a%i==0) return 0; return 1;}int main(){ int n,con原创 2012-08-09 17:29:14 · 3416 阅读 · 0 评论 -
杭电ACM 2056 Rectangles
http://acm.hdu.edu.cn/showproblem.php?pid=2056计算几何水题,x4>x1&&y4>y1&&x3思路就是找出x轴和y轴相交的部分作长和宽,相乘。#include #include using namespace std;double Min(double a,double b){ if(a<b)return a; else ret原创 2012-08-06 17:41:40 · 2779 阅读 · 0 评论 -
杭电ACM 2057 A + B Again
http://acm.hdu.edu.cn/showproblem.php?pid=2057C++提供十六进制加法头文件:#include 说明:是I/O流控制头文件,就像C里面的格式化输出一样 控 制 符 作 用原创 2012-08-06 18:30:19 · 3509 阅读 · 0 评论 -
杭电ACM 2058 The sum problem
http://acm.hdu.edu.cn/showproblem.php?pid=2058穷举,但不能从老老实实从一开始一个一个的穷举,一定要利用好公式,否则会时间超出限制i是开头,j是数字的个数。(i+i+j-1)*j/2=m#include #include using namespace std;int main(){ int N,M; while(ci原创 2012-08-06 19:16:26 · 4091 阅读 · 0 评论 -
杭电ACM 2084 数塔 (动态规划初步)
http://acm.hdu.edu.cn/showproblem.php?pid=2084用递归的方法实现动态规划,状态转移方程。效率低下,重复计算了好多!//不能AC#include using namespace std; int a[110][110];int d(int i,int j,int n){return a[i][j]+(i==n?0:d(i+1,j原创 2012-08-07 21:29:36 · 4631 阅读 · 0 评论 -
杭电ACM 1285 确定比赛名次(拓扑排序)
http://acm.hdu.edu.cn/showproblem.php?pid=1285这里用到了网上找的的拓扑排序的模版。map[i][j]存放有向图的起点i和终点j之间是否连线,=1连线,=0为空。结果的顺序存放在res数组里面。d[i]表示第i个元素的入度,1)入度为零即表示可以读;2)有多个入度为零的点则最终顺序不唯一;3)不存在入度为零的点则顺序不能确原创 2012-08-06 23:53:08 · 2974 阅读 · 0 评论 -
HDU 动态规划(46道题目)倾情奉献
Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱 最脑残的是把总的概率以为是抢N家银行的概率之和… 把状态转移方程写成了f[j]=max{f[j],f[j-q[i].v]+q[i].money}(f[j]表示在概率j之下能抢的大洋转载 2012-08-07 21:50:34 · 1149 阅读 · 0 评论 -
杭电 1176 免费馅饼 (数塔问题)
http://acm.hdu.edu.cn/submit.php?pid=1176数塔问题!这道题注意t可以等于0数组一定要注意,不要开小了!!!递推的方式来构造算法!#include using namespace std;int dp[100010][11];int v[100010][11];int max(int x,int y){ if(x>y) ret原创 2012-08-08 11:05:30 · 1408 阅读 · 0 评论 -
杭电ACM 2081 手机短号
http://acm.hdu.edu.cn/showproblem.php?pid=2081#include using namespace std;int main(){ int N; cin>>N; while(N--){ char a[11]; cin>>a; cout<<'6'; for(int i=6;i<11;i++) cout<<a[i]原创 2012-08-07 19:24:33 · 1780 阅读 · 0 评论 -
杭电ACM 2083 简易版之最短距离
http://acm.hdu.edu.cn/showproblem.php?pid=2083#include #include using namespace std;int a[510];int main(){ int M; cin>>M; while(M--){ memset(a,0,sizeof(a)); int N,sum=0; cin>>N;原创 2012-08-07 20:22:34 · 2322 阅读 · 0 评论 -
hdu 2097 Sky数
http://acm.hdu.edu.cn/showproblem.php?pid=2097进制转换类型的题#include using namespace std;int test(int n,int hex){ int sum=0; while(n){ sum+=n%hex; n=n/hex; } return sum;}int main(){ in原创 2012-08-09 17:43:51 · 1994 阅读 · 0 评论 -
hdu 1716 排列2
http://acm.hdu.edu.cn/showproblem.php?pid=1716坑爹的格式,害了我调了好几个小时!你妹!这道题就是可重集的排列问题,利用递归求解,类似的详见算法竞赛入门经典118页!~~#include #include using namespace std;int flag,flag_fir;void print_permutation(原创 2012-08-09 23:32:13 · 2095 阅读 · 1 评论 -
杭电ACM 2044 一只小蜜蜂
http://acm.hdu.edu.cn/showproblem.php?pid=2044#include using namespace std;int main(){ int N; cin>>N; int a,b; __int64 res[50]; for(int i=1;i<50;i++){ if(i==1) res[i]=1; else if(i==2) r原创 2012-08-02 09:58:47 · 3476 阅读 · 0 评论 -
hdu 1050 Moving Tables && nyoj 220 推桌子
http://acm.hdu.edu.cn/showproblem.php?pid=1050这道题是选择不相交区间问题,要注意把实际问题建模成为基本问题,如房间3和房间4都应“加一除二”转化为2,还要注意输入的两个开始结束值不一定是按大小顺序排列的,如从room10搬到room1,要换过来。按开始时间升序排列,从i=0开始遍历,首先找到未visit的区间,如果找到,则num+=10(指原创 2012-08-27 17:42:08 · 1007 阅读 · 0 评论 -
hdu 1042 N!
高精度问题,好几次超时,最后发现是重复计算了好多。TLE代码:#include #include #define MAX 50000int f[MAX];int main(){ int i,j,n,c,s; while(scanf("%d",&n)!=EOF){ memset(f,0,sizeof(f)); f[0]=1; for(i=1;i<=n;i++){原创 2012-08-11 00:17:42 · 1374 阅读 · 0 评论 -
hdu1753 大明A+B && nyoj 513 A+B Problem IV
高精度问题,我改的自己写的那个高精度模版,c++来写高精度就是麻烦,还要考虑一大堆特殊情况。我用的一些个测试数据:000 00000001.1000 2.9400001.1110 3.3330004.44499.2 0.8100主要的特殊情况就是前导0和后导0,以及全部都是0的情况。我的思路就是:以009.200和00.8 为原创 2012-09-10 16:34:29 · 1649 阅读 · 0 评论 -
hdu 2546 饭卡
http://acm.hdu.edu.cn/showproblem.php?pid=254601背包问题,首先拿出5元买最贵的东西,那接下来就是背包容量m-5,物品数量n-1 的01背包问题了。状态转移方程为:f[j]=max(f[j],f[j-price[i]]+price[i]) , f[j]表示买前i件物品,预算为j时的最大花销 为了好弄,我把最贵的移到数组尾部。#inc原创 2012-09-12 00:20:21 · 5467 阅读 · 1 评论 -
hdu 2602 Bone Collector
http://acm.hdu.edu.cn/showproblem.php?pid=260201背包问题,f[j]表示背包体积为j时候的最大重量状态转移方程:f[j]=max(f[j],f[j-v[i]]+w[i])#include #include using namespace std;int main(){ int T; //freopen("G:/原创 2012-09-12 17:40:41 · 1044 阅读 · 0 评论 -
hdu 1219 AC Me
http://acm.hdu.edu.cn/showproblem.php?pid=1219#include using namespace std;int main(){ char buf[100010]; int n[26]; //freopen("G:/in.txt", "r", stdin); while(gets(buf)){ memset(n,0,s原创 2012-09-12 18:02:52 · 1039 阅读 · 0 评论 -
hdu 1203 I NEED A OFFER!
http://acm.hdu.edu.cn/showproblem.php?pid=1203简单的01背包问题,f[j]表示每个学校都落选的最小概率,状态转移方程 f[j]=min(f[j],f[j-a[i]]*(1-b[i])#include #include #include using namespace std;int main(){ int n,原创 2012-09-12 16:47:07 · 824 阅读 · 0 评论 -
hdu 1027 Ignatius and the Princess II
http://acm.hdu.edu.cn/showproblem.php?pid=1027用递归必然超时,所以我用的STL。可以用STL里面的net_permutation来做。#include #include using namespace std;int main(){ int N, M; while(cin>>N>>M){ int a[1010];原创 2012-08-27 16:57:31 · 776 阅读 · 0 评论 -
杭电ACM 2022 海选女主角
http://acm.hdu.edu.cn/showproblem.php?pid=2022#include using namespace std;int main(){ int m,n,val; int a[100][100]; while(cin>>m>>n){ for(int x=1;x<=m;x++) for(int y=1;y<=n;y++){ cin原创 2012-08-02 10:17:03 · 6465 阅读 · 0 评论 -
杭电ACM 2016 数据的交换输出
http://acm.hdu.edu.cn/showproblem.php?pid=2016#include using namespace std;int find_min(int *a,int i){ int min=0; for(int ix=0;ix<i;ix++){ if(a[ix]<a[min]) min=ix; } return min;}int原创 2012-07-28 17:31:38 · 2288 阅读 · 0 评论 -
杭电ACM 2012 素数判定
http://acm.hdu.edu.cn/showproblem.php?pid=2012#includeusing namespace std;int IsNotSushu(int a){for(int i=2;i<=a/2;i++){if(a%i==0) return 1;}return 0;}int main(){int x,y;while(cin>原创 2012-07-26 17:16:02 · 3596 阅读 · 0 评论 -
杭电ACM 2015 偶数求和
http://acm.hdu.edu.cn/showproblem.php?pid=2015#includeusing namespace std;int main(){ int res[100]; int cont=0; int a[100];// to store the origin numbs int n,m,sum=0,num=0; a[0]=2; fo原创 2012-07-26 19:24:38 · 3002 阅读 · 0 评论 -
hdu 2091 空心三角形’
http://acm.hdu.edu.cn/showproblem.php?pid=2091格式输出还是有问题,以后遇到这种题一定要小心!!我不小心把n=1的情况搞错了~~多输出了一行空行!#include using namespace std;int main(){ char ch; int n,i,j; int flag=0;//空行用 while(c原创 2012-08-12 10:16:08 · 2526 阅读 · 0 评论 -
hdu 2033 人见人爱A+B
http://acm.hdu.edu.cn/showproblem.php?pid=2033#include #include using namespace std;int main(){ int n; int AH,AM,AS,BH,BM,BS; int S,M,H; cin>>n; while(n--){ cin>>AH>>AM>>AS>>BH>>BM>>B原创 2012-08-03 16:01:06 · 1098 阅读 · 0 评论 -
hdu 2085 核反应堆
http://acm.hdu.edu.cn/showproblem.php?pid=2085简单递推#include using namespace std;int main(){ int n; __int64 high[35],low[35]; memset(high,0,sizeof(high)); memset(low,0,sizeof(low)); high[0原创 2012-08-12 15:52:00 · 1466 阅读 · 0 评论 -
杭电ACM 2021 发工资咯:)
http://acm.hdu.edu.cn/showproblem.php?pid=2021#include using namespace std;int main(){ int n; int c100,c50,c10,c5,c2,c1,cont; int a[100]; while(cin>>n&&n!=0){ int i; cont=0; for(i原创 2012-07-28 23:09:05 · 2261 阅读 · 0 评论 -
杭电ACM 2018 母牛的故事
http://acm.hdu.edu.cn/showproblem.php?pid=2018#include using namespace std;int Fun(int n){ int n1[55],n2[55],n3[55],n4[55]; //n4 is muniu //n1 活了1年 //n1 活了2年 //n1 活了3年 for(int ix=原创 2012-07-28 18:41:47 · 3310 阅读 · 0 评论