algorithm
文章平均质量分 81
coder_hsc
这个作者很懒,什么都没留下…
展开
-
上车人数
公共汽车从始发站(称为第1站)开出,在始发站上车的人数为a,然后到达第2站,在第2站有人上、下车,但上、下车的人数相同,因此在第2站开出时(即在到达第3站之前)车上的人数保持为a人。从第3站起(包括第3站)上、下车的人数有一定的规律:上车的人数都是前两站上车人数之和,而下车人数等原创 2011-07-26 17:49:44 · 3357 阅读 · 1 评论 -
老妹的难题
Description【问题描述】 一进家门,你老妹看见了很多精美的礼物,兴奋极了,一不小心,把你的精美礼物撒落一地,你为了让你老妹弥补过失,给她出了一道题。 在洒落的礼物中找出一个,使之到其他礼物的距离之和最小。由于你老妹还没学开根号,所以我们定义(x1,y1)原创 2011-08-04 21:32:30 · 1565 阅读 · 0 评论 -
比赛安排
Description比赛安排(20分) 设有2^n(n使在2^n-1天内每个队都与不同的对手比赛.例如n=2时的比赛安排为: 队 1 2 3 4 比赛 1-2 3-4 第一天 1-3 2-4 第二天 1-4 2-3 第三天 Input原创 2011-08-04 18:53:27 · 1197 阅读 · 0 评论 -
自共轭Ferrers图
Ferrers图是一个自上而下的n层格子,且上层格子数不少于下层格子数。如上图所示,图中的虚线称为Ferrers图的虚轴。若将图一绕虚轴旋转180°,即将第一行与第一列对调,将第二行与第二列对调,……,这样所得到的图仍为Ferrers图,如下图所示。这两个图称为一转载 2011-09-07 21:31:36 · 2285 阅读 · 0 评论 -
hdu 2601 An easy problem
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2601//本题考察的是整数的因子的个数, i * j + i + j =n,即为(i+1)*(j+1)=n+1,转化为了求解n+1的因子的个数//int temp=sqrt(n);这一句放在for循环里面就会超时,真郁闷。 #include#includeusing namespace原创 2011-11-18 17:08:51 · 779 阅读 · 0 评论 -
hdu 2114 Calculate S(n)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2114 主要是计算前n项和的公式。前n项和的立方公式为 : s(n)=(n*(n+1)/2)^2; 前n项和的平方公式为:s(n)=n*(n+1)(2*n+1)/6; 转自百度搜索:公式证明 迭代法: 我们知道: 0次方和的求和公式ΣN^0=N原创 2011-11-24 10:47:08 · 1628 阅读 · 0 评论 -
hdu 2115 I Love This Game
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2115 就是字符串处理排序。。 下面是AC代码: #include#includeusing namespace std;struct node{ char name[20]; char time[20]; int s;} f[20];int原创 2011-11-24 11:21:14 · 948 阅读 · 0 评论 -
hdu 2116 Has the sum exceeded
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2116 编译器为G++会错。。一定要C++; 下面是AC代码#includeusing namespace std;int main(){ int K; while(cin>>K) { __int64 a,b,max=1; scanf("%I64d%I64d",原创 2011-11-24 11:57:11 · 863 阅读 · 1 评论 -
hdu 2117 Just a Numble
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2117 我是纯粹暴力法过的。。。这题应该可以进行优化。比如如果是有限循环的,找到循环周期然后对m取余就可以了。 下面是AC代码:#includeusing namespace std;int f[100001];int main(){ int n,m; int t,l; w原创 2011-11-24 16:54:11 · 854 阅读 · 0 评论 -
hdu 1219 AC Me
。。。水题。。 下面是AC代码:#include #includeusing namespace std;int main(){ int i,x,j; char q[100001]; while(gets(q)) { int a[26]={0}; x=strlen(q); for(i=0;i<x;i++) if(q[i]>='原创 2011-11-26 10:46:30 · 1148 阅读 · 0 评论 -
hdu 2110 Eddy's 洗牌问题
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1210 暴力法。。超时了。。。#includeusing namespace std;int f[100009];int main(){ int n; int t=1; int ans; for(n=1;n<=100001;n++) { ans=0; t=1; wh原创 2011-11-25 20:25:47 · 856 阅读 · 0 评论 -
hdu 1213 How Many Tables
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1213 简单的并查集的应用。。 #includeusing namespace std;int f[1009];int tt[1009];int find(int a){ if(a!=f[a]) f[a]=find(f[a]); return f[a];原创 2011-11-25 22:03:09 · 492 阅读 · 0 评论 -
hdu 1861 游船出租
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1861 纯粹的模拟题。。。 #include#includeusing namespace std;int f[105];int mark[105];int change(char *s){ int hour=0,minute=0,i,len; len=strlen(s);原创 2011-11-25 15:21:19 · 672 阅读 · 0 评论 -
hdu 1862 EXCEL排序
题目: http://acm.hdu.edu.cn/showproblem.php?pid=1862 就是个排序。。代码比较难打。。还是打少了,题目没看仔细。。wrong了两次。 下面是AC代码:#includeusing namespace std;struct node{ char num[10],name[10]; int score;}st[原创 2011-11-25 15:54:10 · 712 阅读 · 0 评论 -
hdu 1212 Big Number
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1212 因为b不大。。可以直接模拟。不用进行大数计算。 下面是AC代码:#includeusing namespace std;int main(){ char a[1009]; int b; int len; while(cin>>a>>b) {原创 2011-11-25 22:45:11 · 615 阅读 · 0 评论 -
hdu 1225 Football Score
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1225 就是对各种结构体排序。。在调用sscanf()函数时应该注意。。。应该加去地址符。。。。如sscanf("12","%c%",&a,&b); 和scanf()函数类似 下面是AC代码: #include#includeusing namespace std;char原创 2011-11-26 22:18:46 · 924 阅读 · 0 评论 -
hdu 1220 Cube
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1220 找规律题。。。关键是求出4个相同顶点的个数,首先容易推出 所有顶点数s(n)=(n-1) + (n-2) ....+1 = > (n-1)*n/2 其中的n为 单位正的个数。第二部求4个相同顶点 的个数可以分成两部分求出。。。第一部分求出n个部分上下之间的4原创 2011-11-26 17:02:53 · 1049 阅读 · 0 评论 -
hdu 1222 Wolf and Rabbit
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1222 水题。根据题目模拟#includeusing namespace std;int main(){ int t; int m,n; cin>>t; while(t--) { cin>>m>>n; if(m==1|原创 2011-11-26 17:22:26 · 436 阅读 · 0 评论 -
hdu 1071 The Area
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1071 抛物线表达式为y= a(x-x1)^2+y1;直线表达式为y=kx+b;面积可通过积分来计算a(x-x1)^2+y1 -(kx+b)下面是AC代码:#include#includedouble x,y,x2,y2,x3,y3;double原创 2011-11-27 11:34:47 · 656 阅读 · 0 评论 -
hdu 1276 士兵队列训练问题
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1276简单的模拟。。按他的要求做就是了。 。但是一开始没考虑到n下面是AC代码:#includeusing namespace std;int f[5009];int main(){ int t; int n,i; while(cin>>t) {原创 2011-11-27 14:52:19 · 2756 阅读 · 0 评论 -
hdu 1872 稳定排序
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1872还是排序。。只要先排序在 标记 两次就可以了。。当成绩不同时 那个排序是错的。当只是姓名不相同时, 那个排序是不稳定的下面是AC代码:#include#include#includeusing namespace std;struct temp{ cha原创 2011-11-27 20:54:51 · 1409 阅读 · 0 评论 -
hdu 1873 看病要排队
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1873这题可以直接数组模拟 也可以用 优先队列。。不会优先队列 所以 整理学习一下。。首先要知道:标准库默认使用元素类型的‘然后常用的调用方法和调用队列类似。。在前面加上priority 就行, //priority_queueint> qi;自定义运算优原创 2011-11-27 21:52:34 · 931 阅读 · 0 评论 -
hdu 1060 Leftmost Digit
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1060思路很简单。就是二分求解。每次只去第一个数。wrong 了很多次。很多细节没注意对于log10()要把里面的数强制转化成double 或者float.还有要把n要用__int64的。。开始觉得int型足够了。。但是好像 大于1亿的时候,在做乘的时候会超过int的范围。#incl原创 2011-11-30 11:30:04 · 641 阅读 · 0 评论 -
hdu 1237 简单计算器
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1237 就是对栈 的应用。。但是在处理细节方面老是出错。 主要有两个错误。在判断栈顶元素和是否加入该栈的元素比较应该用一个while()循环做,而不能用if(),因为if只能判断当前的栈顶,第二个错误就是要对循环里面的元素进行判空处理,否则会越界!!!。 下面是AC代码。有点乱原创 2011-11-24 08:18:55 · 1361 阅读 · 0 评论 -
hdu 1214 圆桌会议
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1214 一开始老是读得不太清楚题意,所以不知道从何入手。 首先这题要思考,对于n个 数在直线上时,需要多少次才能将n个数逆序。例如 将 1234 -> 4321 。可以一步步递推。。。 比如将4提到首位需要3次。3提到首位需要2次。2提到首位需要1次。所以记直线上n个数逆序所需要的原创 2011-11-26 09:16:14 · 869 阅读 · 0 评论 -
hdu 1163 Eddy's digital Roots
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1163开始以为模拟可以通过的。。哪知道超时了。。下面是模拟超时代码:#includeusing namespace std;int n;int str[1000000];int main(){ while(cin>>n,n) { str[0]=n; int len=原创 2011-12-02 20:10:02 · 540 阅读 · 0 评论 -
【金凌模拟试题】 素数密度
【金凌模拟试题】:素数密度Time Limit:10000MS Memory Limit:65536KTotal Submit:20 Accepted:3 Case Time Limit:1500MSDescription- 问题描述 给定区间[L, R](L Input两个数L和R。Output一行,区间中素数的个数。Sample Input原创 2011-12-03 18:55:33 · 2946 阅读 · 0 评论 -
丢失的同学
丢失的同学Time Limit:10000MS Memory Limit:300KTotal Submit:347 Accepted:15DescriptionXX大学里一共有N个学生,某一天有一男一女两个同学失踪了~为了排查到底是哪两个同学,校长让所有在校的同学都去报到,并且签下自己的学号。校长让你写一个程序,计算到底是哪两个同学失踪了呢?Input第1行为整数N(N原创 2011-12-06 22:16:22 · 1934 阅读 · 0 评论 -
常用 STL algorithm
争取把每次遇到的添加进来第一个: sort(); 默认对n个数进行从小到大排列调用方法 sort(a,a+n); //n为需要排序的个数#include#includeusing namespace std;int main(){ int a[4]={4,3,2,1}; sort(a,a+4); for(int i=0;i<4;i++) printf原创 2011-12-10 22:50:02 · 903 阅读 · 0 评论 -
lucky sum of digit
A. Lucky Sum of Digitstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya loves lucky numbers. We all kn原创 2012-02-01 19:47:02 · 2502 阅读 · 0 评论 -
new year sonwmen
New Year Snowmentime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs meticulous Gerald sets the table and ca原创 2012-02-05 11:37:13 · 1023 阅读 · 0 评论 -
VK Cup 2012 Qualification Round 2 C. String Manipulation 1.0
C. String Manipulation 1.0time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne popular website developed an原创 2012-03-10 18:16:02 · 1189 阅读 · 1 评论 -
hdu 1598
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1598可以用并查集,也可以用二分+单元最短距离做。思路都差不多。都是枚举上下界。先将速度排序。然后枚举上界,添加其他节点。如果能使a->b联通,那么当前这个舒适值就是上界-新添加的这个节点(使a-b联通的)。然后求一个最小值就行了。下面是AC代码:#include#incl原创 2012-09-04 15:31:08 · 718 阅读 · 0 评论 -
hdu 1575
http://acm.hdu.edu.cn/showproblem.php?pid=1575矩阵乘法+快速求幂 #include#includeusing namespace std;const int maxn = 15;#define mod 9973int res[maxn][maxn];int n;void mul(int a[][15],int原创 2012-11-10 23:23:01 · 1186 阅读 · 0 评论 -
《算法竞赛入门经典——训练指南》实用数据结构
基础数据结构例题例题1UVa11995 ACI Can Guess the Data Structure!ADT 题解例题2UVa11991 ACEasy Problem from Rujia Liu排序或者善用STL 题解例题3LA3135 AC原创 2012-12-06 10:29:38 · 4078 阅读 · 0 评论 -
hdu 1128 Self Numbers
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1128水题。直接暴力AC#include#define MAXN 1000010char f[MAXN];int N;int func(int e){ int sum=0,tmp=e; while(tmp) { sum+=tmp%10; tmp/=10;原创 2011-12-02 19:25:37 · 860 阅读 · 0 评论 -
hdu 1062 Text Reverse
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1062就是翻转字符串。。。虽然是水题但是容易出现presention error。最后一个不能多空格。下面是AC代码:#includeusing namespace std;int main(){ int t,i,j; char str[1001]; cin>>t原创 2011-12-03 16:53:56 · 771 阅读 · 0 评论 -
hdu 1009 FatMouse' Trade
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1009贪心类水题。直接按交换单价排序就可以。下面是AC代码:#includeusing namespace std;typedef struct{ double j,f; double k;}cat;cat a[10002];int cmp(const voi原创 2011-12-04 13:19:55 · 512 阅读 · 0 评论 -
hdu 1871 无题
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1871水题。。排序处理即可下面是AC代码:#include#include#includeusing namespace std;struct ss{ int num; int ren; int money;}s[1001];int c;int cmp(原创 2011-11-27 20:42:06 · 874 阅读 · 0 评论 -
HDU 2258
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2258跟HDU 3295 是一样的消去方法。。感觉这题比 3295还容易点,可能是因为先打3295,总体思路差不多所以感觉容易点了。= =!。。直接按题意模拟即可。。没什么细节问题。下面是AC代码:#include#include#include#inclu原创 2012-08-22 23:24:24 · 735 阅读 · 0 评论