随笔分类 -  acm

上一页 1 ··· 4 5 6 7 8
HDU2544最短路(最短路 Dijkstra, spfa)
摘要:题目连接。解题:题中的起始点为0(假设元素从0开始),终止点为n-1Dijkstra:View Code //起始为0,终点为n-1#include <stdio.h>#include <limits.h>#include <string.h>#define MAXN 102#define INF (1<<20) //如果很小的话。是不能AC的。int v[MAXN], d[MAXN], w[MAXN][MAXN];void Dijkstra(int n){ memset(v, 0, sizeof(v)); int i, y; for(i=0; 阅读全文
posted @ 2013-02-01 13:27 Still_Raining 阅读(286) 评论(0) 推荐(0)
HDU1863畅通工程(最小生成树 Kruskal)
摘要:题目链接。#include <stdio.h>#include <stdlib.h>#define MAXN 5000int v[MAXN], u[MAXN], p[101], w[MAXN], r[MAXN];int find(int x){return p[x] == x ? x : (p[x] = find(p[x]));}int comp(const void *a, const void *b){ int x = *(int *)a, y = *(int *)b; return w[x] - w[y];}int main(){ int n, m, i, s, 阅读全文
posted @ 2013-01-28 20:58 Still_Raining 阅读(221) 评论(0) 推荐(0)
1232畅通工程(并查集)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1232#include <stdio.h>#include <stdlib.h>#define MAXN 2000int v[MAXN], u[MAXN], p[MAXN];int icount;int find_f(int x){return p[x] == x ? x : (p[x]=find_f(p[x]));}int main(){ int n, m, i; while(scanf("%d", &n) == 1 && n != 0){ 阅读全文
posted @ 2013-01-28 20:09 Still_Raining 阅读(220) 评论(0) 推荐(0)
HDU1233还是畅通工程(最小生成树 Kruskal算法)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1233//结构体做法#include <stdio.h>#include <stdlib.h>#include <string.h>int p[101],sum,num; //p为并查集struct edge//图的结构体{ int sv,ev,w;//起始边,终边,权值。};struct edge e[10000];//必须开到大于(n*n-1)/2,否则必然RE。。。int comp(const void *a,const void *b){ return (*(str 阅读全文
posted @ 2013-01-27 20:51 Still_Raining 阅读(872) 评论(0) 推荐(0)
表达式树
摘要:#include <stdio.h>#include <string.h>#define maxn 1000//const int maxn = 1000;int lch[maxn], rch[maxn]; char op[maxn];int nc = 0;int build_tree(char *s, int x, int y){ int i, c1 = -1, c2 = -1, p = 0; int u; if(y-x == 1){ u = ++nc; lch[u] = rch[u] = 0; op[u] = s[x]; retu... 阅读全文
posted @ 2013-01-26 17:28 Still_Raining 阅读(169) 评论(0) 推荐(0)
UVA 10106 - Product
摘要:10106 - ProductThe ProblemThe problem is to multiply two integers X, Y. (0<=X,Y<10250)The InputThe input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.The OutputFor each input pair of lines the output line should consist one integer the product.Sample Input 阅读全文
posted @ 2013-01-12 16:46 Still_Raining 阅读(197) 评论(0) 推荐(0)
Integer Inquiry
摘要:Integer Inquiry地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=97&problem=365&mosmsg=Submission+received+with+ID+11121758One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers 阅读全文
posted @ 2013-01-10 20:47 Still_Raining 阅读(191) 评论(0) 推荐(0)
N的阶乘中末尾有几个0
摘要:原地址N的阶乘中末尾有几个0 N的阶乘中末尾有几个0:如果N!= K×10M,且K不能被10整除,那么N!末尾有M个0。再考虑对N!进行质因数分解,N!=(2^x)×(3^y)×(5^z)…,由于10 = 2×5,所以M只跟X和Z相关,每一对2和5相乘可以得到一个10,于是M = min(X, Z)。不难看出X大于等于Z,因为能被2整除的数出现的频率比能被5整除的数高得多,所以把公式简化为M = Z。int count(int k) { int sum=0; while(k!=0) { k=k/5; sum+=k; ... 阅读全文
posted @ 2012-12-14 20:34 Still_Raining 阅读(618) 评论(0) 推荐(0)
dfs
摘要:其实玩游戏也得学程序题目地址:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2465只是用DFS练练手而已。()。//head file#include <stdio.h>#include <string.h>#include <stdlib.h>//definition#define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define OK 1#define ERROR 0#define TRUE 1# 阅读全文
posted @ 2012-12-12 18:39 Still_Raining 阅读(292) 评论(0) 推荐(0)
走迷宫
摘要:走迷宫Time Limit: 1000MS Memory limit: 65536K题目描述一个由n * m 个格子组成的迷宫,起点是(1, 1), 终点是(n, m),每次可以向上下左右四个方向任意走一步,并且有些格子是不能走动,求从起点到终点经过每个格子至多一次的走法数。输入 第一行一个整数T 表示有T 组测试数据。(T <= 110)对于每组测试数据:第一行两个整数n, m,表示迷宫有n * m 个格子。(1 <= n, m <= 6, (n, m) !=(1, 1) ) 接下来n 行,每行m 个数。其中第i 行第j 个数是0 表示第i 行第j 个格子可以走,否则是1 阅读全文
posted @ 2012-11-10 20:58 Still_Raining 阅读(146) 评论(0) 推荐(0)
鹊桥相会
摘要:鹊桥相会Time Limit: 1000MS Memory limit: 65536K题目描述一年一度的七夕又要到了,可歌可泣的牛郎织女又可以在鹊桥相会了。不知道大家有没有雅兴陪redraiment坐在葡萄藤下倾听他们的对话。我们知道,牛郎要与织女相见,必须要有喜鹊搭桥。所以,牛郎必须在天河岸上等待,直到有喜鹊经过,于是牛郎可以搭乘这只喜鹊往河对岸走。当然,牛郎急着去见织女,所有在途中,如果有速度更快的喜鹊赶上了他,他就会换乘那只速度更快的喜鹊。我们可以假定喜鹊的速度是恒定不变的,并且喜鹊一直是沿直线飞行的(不转弯,更不回头),牛郎坐上喜鹊所花的时间忽略不计。现给出天河的宽度、每只喜鹊的初始位 阅读全文
posted @ 2012-10-24 20:46 Still_Raining 阅读(322) 评论(0) 推荐(0)
汉诺塔
摘要:汉诺塔Time Limit: 1000MS Memory limit: 65536K题目描述汉诺塔(又称河内塔)问题是印度的一个古老的传说。开天辟地的神勃拉玛在一个庙里留下了三根金刚石的棒A、B和C,A上面套着n个圆的金片,最大的一个在底下,其余一个比一个小,依次叠上去,庙里的众僧不倦地把它们一个个地从A棒搬到C棒上,规定可利用中间的一根B棒作为帮助,但每次只能搬一个,而且大的不能放在小的上面。僧侣们搬得汗流满面,可惜当n很大时这辈子恐怕就很搬完了。聪明的你还有计算机帮你完成,你能写一个程序帮助僧侣们完成这辈子的夙愿吗?输入输入金片的个数n。这里的n<=10。输出输出搬动金片的全过程。格 阅读全文
posted @ 2012-10-21 21:23 Still_Raining 阅读(271) 评论(0) 推荐(0)
Lowest Bit(虽然很简单)
摘要:Lowest BitTime Limit: 1000MS Memory limit: 65536K题目描述Given an positive integer A (1 <= A <= 100), output the lowest bit of A.For example, given A = 26, we can write A in binary form as 11010, so the lowest bit of A is 10, so the output should be 2.Another example goes like this: given A = 88, 阅读全文
posted @ 2012-10-21 16:46 Still_Raining 阅读(241) 评论(0) 推荐(0)
约瑟夫问题
摘要:约瑟夫问题Time Limit: 1000MS Memory limit: 65536K题目描述 n个人想玩残酷的死亡游戏,游戏规则如下:n个人进行编号,分别从1到n,排成一个圈,顺时针从1开始数到m,数到m的人被杀,剩下的人继续游戏,活到最后的一个人是胜利者。请输出最后一个人的编号。输入输入n和m值。输出输出胜利者的编号。示例输入5 3示例输出4提示第一轮:3被杀第二轮:1被杀第三轮:5被杀第四轮:2被杀View Code #include <stdio.h>int IsEnd(int a[],int n);//测试就剩一个入?如果是。就返回序号。否则返回0int main(){ 阅读全文
posted @ 2012-10-16 15:09 Still_Raining 阅读(277) 评论(0) 推荐(0)
排序问题
摘要:排序问题Time Limit: 1000MS Memory limit: 65536K题目描述输入10个整数,将它们从小到大排序后输出,并给出现在每个元素在原来序列中的位置。输入输入数据有一行,包含10个整数,用空格分开。输出输出数据有两行,第一行为排序后的序列,第二行为排序后各个元素在原来序列中的位置。示例输入1 2 3 5 4 6 8 9 10 7示例输出1 2 3 4 5 6 7 8 9 10 1 2 3 5 4 6 10 7 8 9源码(用结构体):#include <stdio.h> struct data { int n;//数值 int cur;//位置 }; int 阅读全文
posted @ 2012-10-14 11:40 Still_Raining 阅读(269) 评论(0) 推荐(0)
C语言实验——打印金字塔
摘要:题目描述输入n值,打印下列形状的金字塔,其中n代表金字塔的层数。输入输入只有一个正整数n。输出打印金字塔图形,其中每个数字之间有一个空格。示例输入3示例输出 1 1 2 1 1 2 3 2 1源码(程序不太简洁。。凑合吧):#include <stdio.h> int main() { int n,i,j; int t; scanf("%d",&n); t=2*n-1; for(i=1; i<=n; i++)//一次循环代表输出一行 { for(j=1; j<=t-2*i; j++) putchar(' '); for(j=1 阅读全文
posted @ 2012-10-14 11:08 Still_Raining 阅读(3687) 评论(0) 推荐(0)
C语言实验——各位数字之和排序
摘要:C语言实验——各位数字之和排序题目描述给定n个正整数,根据各位数字之和从小到大进行排序。输入输入数据有多组,每组数据占一行,每行的第一个数正整数n,表示整数个数,后面接n个正整数。当n为0时,不作任何处理,输入结束。输出输出每组排序的结果。示例输入2 1 2 3 121 10 111 0示例输出1 2 10 111 121注意题目为各位数字之和,不注意是会吃大亏的。。。#include <stdio.h> void sort(int a[],int n);//冒泡排序 int isum(int n);//各位之和 int main() { int n,i; int a[100]; 阅读全文
posted @ 2012-10-09 20:33 Still_Raining 阅读(1007) 评论(0) 推荐(0)
十点半
摘要:*十点半题目描述 十点半是一个纸牌游戏,或者说数字游戏。这里简化一下,规则是每个人摸两张牌,然后只通过加减运算,如果能够得到十点半的话就算赢,否则就输。扑克从2到K分别代表2~13点,A代表半点,然后王或老头或司令随便你怎么叫,不分大小,都代表半点。输入输入有多组数据。第一行一个正整数T代表数据的组数。接下来N行,每行两张牌。其中11到13的牌是J,Q,K,王是S。输出 输出也要N行,每行的格式是如果赢了Case P: WIN,输了Case P: LOSE。其中P代表是第几组数据。示例输入410 AA J10 S2 8示例输出Case 1: WINCase 2: WINCase 3: ... 阅读全文
posted @ 2012-10-09 10:57 Still_Raining 阅读(474) 评论(0) 推荐(0)
C语言实验——数日子
摘要:输入输入数据有多组,第一行是数据的组数n,下面n行是n组数据,每组数据由3个正整数组成,分别为年、月、日,我们保证每组数据都是有效的日期。输出输出所输入的日期是这一年的第几天。#include <stdio.h>int trans(int year,int month,int day);int IsRun(int n);//判断是否为闰年int main(){ int n; int year,month,day; int i; scanf("%d",&n); for(i=0; i<n; i++) { scanf("%d %d %d&quo 阅读全文
posted @ 2012-10-09 10:13 Still_Raining 阅读(560) 评论(0) 推荐(0)
C语言实验——分割整数
摘要:题目描述从键盘输入一个长整数(不超过10位),从高位开始逐位分割并输出。输入正整数n,不含前导零。输出分割的整数序列,各整数之间用空格格开。注意,最后一个数字后面没有空格!示例输入654321示例输出654321//源码:#include <stdio.h>#include <string.h>void get_num(int n);int main(){char a[10];scanf("%s",a);for(int i=0; i<strlen(a); i++){if( i != strlen(a)-1 )printf("%c &q 阅读全文
posted @ 2012-10-09 10:11 Still_Raining 阅读(1281) 评论(0) 推荐(0)

上一页 1 ··· 4 5 6 7 8