
HDU
gneveek
T_T此号终于找回,以后要注意安全。
展开
-
HDU - 2037 今年暑假不AC
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2037思路:用一个结构体tim来存时间段a,b 和他们的差sub (时间段的最小单位是1,比如 输入数据中1 3,则这个时间段为1~2,2~3,这个单位是什么不知道,反正不是小原创 2011-10-11 19:11:14 · 1196 阅读 · 0 评论 -
hdu1097
http://acm.hdu.edu.cn/showproblem.php?pid=1097思路:只算a的最后一位的b次方就可以了,算的中间结果也只取最后一位继续…… 然后就会出现循环 比如8的800次方,8^1 % 10 = 8; 8^2 % 10 = 4; 8^3 % 10 = (8^2%10) *8%10 = 6; ..................原创 2012-05-28 17:43:05 · 2606 阅读 · 0 评论 -
istringstream用法,HDU1106排序
http://acm.hdu.edu.cn/showproblem.php?pid=1106#include #include #include using namespace std;string s;int data[600];int intCmp(const void *a, const void *b){ return *(int *)a - *(in原创 2012-05-29 14:26:03 · 940 阅读 · 0 评论 -
HDU1877 又一版 A+B
注意最大和最小值就OK了。SampleInput:8 1300 482 1 72 2147483647 21474836472 0 00SampleOutput:25041000111111111111111111111111111111100#include #define MAXN 35using namespace std;int原创 2012-05-25 20:45:07 · 1221 阅读 · 0 评论 -
hdu1976
#include using namespace std;int main(){ freopen("in.txt","r",stdin); int t; cin >> t; int a1,a2,a3,b1,b2,b3; while(t--) { cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3; if(a1 > b1) cout原创 2012-05-25 21:22:03 · 928 阅读 · 0 评论 -
hdu1898 Sempr == The Best Problem Solver?
水题#include using namespace std;int main(){ freopen("in.txt","r",stdin); int a,b,t; int n; cin>>n; while(n--){ cin >> a >> b >> t; if(t%a > t%b) cout << "Xiangsanzi!"; else if原创 2012-05-25 21:06:25 · 933 阅读 · 0 评论 -
HDU-2037今年暑假不AC(贪心算法)
http://acm.hdu.edu.cn/showproblem.php?pid=2037以节目结束时间作为贪心搜索的依据。证明贪心算法在此问题中适用:(反证法)如图所示……AC代码:#include using namespace std;int int_comp(const void *a, const void原创 2012-07-11 10:26:54 · 1319 阅读 · 0 评论 -
HDU_1804_Deli Deli (字典树)
http://acm.hdu.edu.cn/showproblem.php?pid=1804#include #include const int words_max_length = 23; //单词的最大长度,题目给的是20struct node{ node * child[26]; char word[words_max_length]; node(){memse原创 2012-07-17 15:15:31 · 889 阅读 · 0 评论 -
HDU 2846 字典树
算法步骤:1.读取n,n表示商品数量,即单词的个数2.对每个单词进行循环插入操作,比如ade,就把ade,ad,e都插入字典树中3.插入函数insert():两个参数,第一个是单词首地址,第二个是当前插入单词的id( 第几个插入进树的单词),然后逐字符的对单词扫描,以ade为例,首先指针next指向Root,如果Root->child[*word-'a']这个子孩子不存在原创 2012-08-08 11:25:31 · 1055 阅读 · 0 评论 -
hdu_OJ_2222
// 题目:hdu_2222// 地址:http://acm.hdu.edu.cn/showproblem.php?pid=2222// 状态:Accept/** * 这题是用字典树做的,效率不太高,其中还有很多地方有待优化 * * 缺陷:每个实例都重新建一颗字典树,没有释放资源,如果测试实例太多,将占用大量内存。 */#include #include struct n原创 2012-07-23 15:09:24 · 1734 阅读 · 0 评论 -
HDU 1075
/* ***************************************************** * 题目:HDU 1075 * 地址:http://acm.hdu.edu.cn/statistic.php?pid=1075 * 状态:AC ***************************************************** *原创 2012-07-25 15:54:33 · 1604 阅读 · 0 评论 -
HDU1671 Phone List(必须删除字典树,否则Memory Limit Exceeded)
简单的字典树题 目,但是这题有多组测试实例,所以每次建立完的字典树都要删除掉,开始时没删,结果内存超了8MB左右 加了delete操作后内存占用从39MB降到了3320K删除用的是递归,是参考Discuss里的方法,之前自己用非递归写的,很麻烦,效果也不好,在此谢过分享代码的同学下面是AC的代码:// hdu1671#include #include原创 2012-07-27 17:45:58 · 1439 阅读 · 0 评论 -
HDU 2896 病毒侵袭
这题 可用字典树做,也可用AC自动机做,需要注意的是,ASCII可见字符包括从33~126的字符,0~32 和127均为不可见字符(控制字符和换行,空格之类的)所以在构造字典树的时候,可以让节点的子孩子数定义为 127 - 33 = 94struct node{ int number; //病毒编号 node * child[94]; //ASCII可见字符原创 2012-07-28 15:11:13 · 1903 阅读 · 0 评论 -
hdu2153
//Problem:hdu2153//Data:#include #include using namespace std;int main(){ //freopen("E:\\in.txt","r",stdin); int n,i,j; int data[40000]; for(i=0; i<40; i++) data[i] = i; whi原创 2011-11-02 00:31:25 · 1026 阅读 · 0 评论 -
HDU 2502 - 月之数
常规思路:n位二进制数的总个数C(n-1,0) + C(n-1,1) + C(n-1,2) +.....+C(n-1,n-1) = 2^(n-1)其中C(n-1,1) 是组合每位的第一位必须是1, 所以先把这个1算进去.int total = 0; //总数初始化为0total += 2^(n-1); //把上在讲的那种情况的1先算进来 然后后面的1可以这样算:C(n原创 2011-11-02 12:53:59 · 1920 阅读 · 1 评论 -
HDU 2510 - Tiling_easy version
本题的递推公式:data[i] = data[i-1] + 2*data[i-2];分析:data[i] 相比于 data[i-1], 后面多了一个格,只要对这个新增加的格子进行分析,就可以得出递推关系分三种情况:1.这个格竖着放一个2*1的骨牌,这种情况和data[i-1] 数量相同2.这个新增加和格和它前面那个格合起来放一个2*2的骨牌,这种情况和data[i-2]的数原创 2011-11-02 10:27:15 · 1945 阅读 · 0 评论 -
HDU 2031
#includeusing namespace std;int main(){ int n,r; char result[35]; const char alpha[6] = {'A','B','C','D','E','F'}; while(cin>>原创 2011-10-15 15:02:11 · 1581 阅读 · 0 评论 -
HDU - 2020
这个题本来没必要贴出来,但发现了qsort竟然还可以对结构排序啊说到底还是对qsort()的原理不清楚,只知道用。最近烦心事也一大堆,不想深究,以后有状态了再说吧。下面是代码,开始用qsort直接排一个int,结果当然乱套,后来改为2*sizeof(int),奇迹出现了。原创 2011-10-09 22:12:43 · 1605 阅读 · 1 评论 -
HDU 1014
题很长,看起来挺唬人的,其实是纸老虎。大意就是给出两个数,STEP , MOD然后根据给出的递推公式算一下 0~ mod-1之间的数是否都有出现过,如果都出现了,那就是Good 否则bad初始种子不只是0,可以取0~mod-1之间的所有数,所以要用一个循环检验所有情况 //Problem:hdu1014//Data:2011/10/30#include #include原创 2011-10-30 18:06:13 · 2287 阅读 · 0 评论 -
HDU 1017
超水的题//Problem:hdu1017//Data:2011/10/30#include using namespace std;int main(){ //freopen("E:\\in.txt","r",stdin); int N; cin >> N; while(N--) { int cas = 1; int n,m; int a,b;原创 2011-10-30 21:36:51 · 3411 阅读 · 0 评论 -
HDU 2028最小公倍数LCM 最大公约数GCD
最小公倍数(LCM)最大公约数(GCD)LCM(a, b) = a * b / GCD(a,b);或者: lcm(a, b) = a/gcd(a,b) * b; // 这个可以防溢出 // hdu 2028#includeusing namespace std;int gcd(int a, int b);int lcm(int a, int b);int m原创 2011-10-14 21:40:31 · 1362 阅读 · 0 评论 -
hdu 1005
这题不能直接按公式用递归来求,因为n最大可以达到100,000,000,会栈溢出所以要找规律前两个等于1,所以后面如果有两个连着的1出现,那就是出现周期了代码如下://Problem:hdu1005//Data:2011/10/30#include using namespace std;int arr[10000]; int main(){ int A,B,n原创 2011-10-30 12:26:45 · 6738 阅读 · 6 评论 -
hdu 1013
这题测试数据可能会很长,所以不能简单的用传统方法考虑用处理字符串的方式来进行,但开数组也没完没了的,所以就直接对每一个字符来处理即,每得到一个字符马上加到 sum 上去(sum是结果),如果sum大于9了,马上对sum进行处理,个位和十位相加令其变为一个数(结果一样)代码如下:#include using namespace std;int main(){ //freop原创 2011-10-30 16:35:15 · 2699 阅读 · 0 评论 -
hdu1019
这题因为没看清题意,WA了7次妈的太恶心了!下面每行测试实例中,第一个数字竟然是后面数字的个数! 之前一直把它也算进去,结果无限WA啊 亏得还想各种办法弄“不指定个数的输入”问题,即用getchar()看是否到\n了,又用sstream串流类的还是WA, 晕死不过还能收获个新用法,从数组中读数据,这玩意儿相当高档啊#include#include#include /原创 2011-10-30 23:18:57 · 2110 阅读 · 0 评论 -
Hdu 1004
//Problem:hdu1004//Data:2011/10/30#include using namespace std;//颜色结构,num用来计算每种颜色出现的次数 struct Color{ int num; char color[16]; };Color input[1000] = {0,""};//按降序排序 int int_cmp(const void原创 2011-10-30 12:19:45 · 4990 阅读 · 1 评论 -
HDU 1200
//Problem:hdu1200//Data:2011.11.1#include using namespace std;char line[220];int main(){ //freopen("E:\\in.txt","r",stdin); int n,i,j; char c; bool flag; while(cin>>n, n) {原创 2011-11-01 13:26:37 · 1073 阅读 · 0 评论 -
HDU 1201 18岁的生日
//Problem:hdu1201//Data:2011 11 1#include using namespace std;bool isleapYear(int year){ if(year%4==0 && year%100!=0 || year%400==0) return true; else return false;}int m原创 2011-11-01 21:03:57 · 1278 阅读 · 0 评论 -
HDU 1228
//Problem:hdu1228//Data:2011/11/1#include #include using namespace std;const string data[10] = {"zero","one","two","three","four","five","six","seven","eight","nine"};int maps(string k原创 2011-11-01 13:24:56 · 1327 阅读 · 0 评论 -
HDU 水题 1859 1860 1862
hdu 1859#include struct Point{ int x,y;}min,max,tmp;int main(void){ while( scanf("%d %d",&tmp.x, &tmp.y), tmp.x!=0 || tmp.y!=0 ) { min.x = tmp.x; min.y = tmp.y; max.x = tmp.x;原创 2012-09-17 15:22:15 · 1888 阅读 · 0 评论