
----------HDU----------
xmzyt1996
这个作者很懒,什么都没留下…
展开
-
【HDOJ 1001】 Sum Problem
Problem DescriptionHey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. InputThe input will co原创 2014-12-12 21:08:54 · 353 阅读 · 0 评论 -
HDU 2795 Billboard // 线段树 单点更新
题目描述HDU 2795 Billboard解题思路题目大意: 有一张h×w的矩形告示栏, 和 n 张 1×wi 的海报 海报每次张贴的位置为告示栏剩余位置的左上角. 要求支持下列操作: 1) 对于每张海报 输出其在告示栏的第几行 (若放不下, 则输出 -1)首先我们知道的是 告示栏上的海报最多只有n张, 即告示栏的行数最多只有n行有效 所以当输入的h大于n时, 令h = n 即可.原创 2015-08-16 22:11:16 · 319 阅读 · 0 评论 -
HDU 5387 Clock // 模拟
题目描述HDU 5387 Clock解题思路题目大意: 给出时间 hh:mm:ss ,求 时针, 分针, 秒针 两两夹角.我们可以先计算出 0点 与 每根针 的夹角(顺时针方向 , 夹角[0, 360) ) 然后做差即可.参考代码#include <cstdio>inline int abs(int x){return x < 0 ? -x : x;}inline int gcd(int a,原创 2015-08-13 23:30:00 · 422 阅读 · 0 评论 -
HDU 1754 I Hate It // 线段树
题目描述HDU 1754 I Hate It解题思路支持两种操作: 1) 区间最值查询 2) 单点更新 这题跟 HDU 1166 敌兵布阵 是类似的思路.参考代码#include <stdio.h>#define lson rt<<1#define rson rt<<1|1#define mid ((l+r) >> 1)inline int max(int a, int b){retu原创 2015-08-16 16:19:35 · 409 阅读 · 0 评论 -
HDU 1394 Minimum Inversion Number // 线段树求逆序数
题目描述HDU 1394 Minimum Inversion Number解题思路题目大意: 给出0~n-1的一个排列,每次可以把前m个数放在后面,eg: a1{a}_{1}, a2{a}_{2}, …, an−1{a}_{n-1}, an{a}_{n} (m=0)(m = 0 ) a2{a}_{2}, a3{a}_{3}, …, an{a}_{n}, a1{a}_{1}原创 2015-08-16 18:06:46 · 364 阅读 · 0 评论 -
HDU 4417 Super Mario // 线段树
题目描述HDU 4417 Super Mario解题思路题目大意: 查询区间 [l, r] 有多少个数 <= h.之前只接触过一点线段树, 所以还是来一发线段树吧= =|参考代码#include <iostream>#include <cstdio>#include <vector>#include <algorithm>#define MAX_N 100010#define Lson i原创 2015-08-10 22:40:10 · 355 阅读 · 0 评论 -
HDU 1166 敌兵布阵 // 线段树
题目描述HDU 1166 敌兵布阵解题思路线段树的入门基础题. 题目要求支持下列操作: 1) 区间查询 (求和) 2) 单点更新 (加\减) // 具体还是看注释哈~^ ^参考代码#include <stdio.h>#define lson rt<<1 // 左儿子的下标#define rson rt<<1|1 // 右儿子的下标#define mid ((l + r) >>原创 2015-08-16 15:34:58 · 413 阅读 · 0 评论 -
HDU 4286 Data Handler // 模拟链表
题目描述HDU 4286 Data Handler解题思路有一段区间和 两个指针(L 和 R) 要求支持下列操作: 1) 指针左移 2) 指针右移 3) 在指针所指位置插入一个数 4) 删除指针所指位置上的数 5) 反转 指针L 和 R 形成的区间可以将区间分成三段( [0, L) [L, R] (R, n] )考虑, 对每个区间用一个双端队列来维护. 对于反转操作,如果每次真的去反转原创 2015-08-16 17:34:34 · 371 阅读 · 0 评论 -
POJ 2528 Mayor's posters // 线段树 区间更新 离散化
题目描述POJ 2528 Mayor’s posters解题思路题目大意: 在墙上贴海报,海报可以互相覆盖,问最后可以看见几张海报?首先数据量较大,应该进行离散化,然后进行线段树的区间更新和查询. 但这题的难点在于每个数字其实表示的是一个单位长度(并非一个点),这样普通的离散化会造成许多错误 给出下面两个简单的例子应该能体现普通离散化的缺陷: eg1: [1, 10] [1, 5] [原创 2015-08-17 22:26:19 · 358 阅读 · 0 评论 -
HDU 1698 Just a Hook // 线段树 区间更新
题目描述HDU 1698 Just a Hook解题思路题目大意: 每段区间有三类状态: 值为1, 2, 3 要求支持下列操作: 1) 修改区间的状态, 然后输出整个区间[1, n]的和 线段树成段更新的入门题, 具体看注释哈~参考代码#include <stdio.h>#define lson rt<<1#define rson rt<<1|1#define mid ((l+r) >原创 2015-08-16 22:32:59 · 346 阅读 · 0 评论 -
HDU 4122 Alice's mooncake shop // RMQ 线段树
题目描述HDU 4122 Alice’s mooncake shop解题思路题目大意: 有一家24小时营业的月饼店, 会连续营业m个小时, 且月饼每个小时的单价会浮动.在第i个小时会有一份订单.订单可以现做,也可以提前做好保存在冰箱里,(放在冰箱里每小时会花费一定的费用,且月饼有保质期为T).问在满足所有订单的前提下,最少的制作费用是多少?抽象出来就是,对于第i个小时的订单. 查询区间 [i-T,原创 2015-08-19 23:24:43 · 437 阅读 · 0 评论 -
HDU 1075 What Are You Talking About // 字符串映射,Trie
题目描述HDU 1075 What Are You Talking About解题思路题目大意: 给一些单词及其翻译,然后再输入一个句子,对其进行翻译,若句子中的某个单词不存在翻译,则原样输出,其中标点符号也是原样输出。建Trie树跑一遍,然后需要注意的是:【句子中某个单词A 是以 字典中某个单词B的前缀出现,但是字典里却没有单词A】这种情况.比如说: STRAT earth fnnvk E原创 2015-10-25 23:33:08 · 464 阅读 · 0 评论 -
HDU 1247 Hat’s Words // Trie, 枚举
题目描述HDU 1247 Hat’s Words解题思路题目大意: 判断一个单词是否能由字典中其它两个单词组合而成。 枚举每个单词所有的组合,然后查找分解出来的两个单词是否都存在于字典中即可。参考代码//**********************************************// Author: @xmzyt1996// Date: 2015-10-15//原创 2015-10-25 23:42:48 · 358 阅读 · 0 评论 -
HDU 1251 统计难题 // Trie入门题
题目描述HDU 1251 统计难题解题思路题目大意: 统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀)。对每个节点维护cnt,记录经过此节点的次数,然后访问前缀所在节点的cnt即可。参考代码#include <stdio.h>#include <string.h>#include <stdlib.h>struct Trie { Trie* next[26]; in原创 2015-10-25 22:20:25 · 371 阅读 · 0 评论 -
HDU 3172 Virtual Friends // 并查集,字典树
题目描述HDU 3172 Virtual Friends解题思路题目大意: 每次输入两个人A、B,代表两人成为朋友,那么两人所在的圈子将合并成一个新的圈子,输出这个新圈子的人数。 用字典树给名字分配编号,然后用并查集维护集合(圈子)关系即可。参考代码//**********************************************// Author: @xmzyt1996//原创 2015-10-26 23:00:10 · 435 阅读 · 0 评论 -
HDU 1800 Flying to the Mars // Trie
题目描述HDU 1800 Flying to the Mars解题思路题目大意: 每个士兵都有各自的能力值,能力强的可以教能力弱的人 “骑扫帚”,两人用的是同一把扫帚 (若A B 用 一把, B C 用一把, 则说明 A B C用同一把)。另外题目要求每个士兵最多只能有一个学生或最多只能有一个老师。最后输出最少需要多少扫帚~不难知道,若n的士兵能力值各不相同的话,则他们只需要一把扫帚。因此,最终扫原创 2015-10-26 23:42:41 · 418 阅读 · 0 评论 -
HDU 1298 T9 // 字典树,枚举,dfs
题目描述HDU 1298 T9解题思路题目大意: 给出一些单词,及其出现的频率。然后再输入九宫格键盘中的数字(2~9),然后每次按下一个键,输出此刻联想到的单词(单词频率大的优先,频率相同的话,字典序小的优先)。 另外 比如 说 “hell 4”, “hello 7”, and “hellfire 3”, 则hell出现的频率不是0, 而是4+7+3 = 14!!参考代码//**********原创 2015-10-26 23:56:34 · 489 阅读 · 0 评论 -
HDU 4291 A Short problem // 矩阵快速幂, 循环节
题目描述HDU 4291 A Short problem解题思路题目大意:g(n)g(n) = 3g(n−1)g(n - 1) + g(n−2)g(n - 2) 其中, g(0)g(0) = 0, g(1)g(1) = 1求 g(g(g(n)))g(g(g(n))) mod 1000000007将递推关系变形为 : (g(n+1)g(n))\begin{pmatrix} g(n+1) \\原创 2015-08-12 22:43:56 · 407 阅读 · 0 评论 -
HDU 5373 The shortest problem //模拟
题目描述HDOJ 5373 The shortest problem解题思路题目大意: 给一个数n, 比如123, 每次操作后把之前各位数字之和加到末尾 由于1+2+3 = 6 所以 123->1236 类似得到1236->123612->… 问,经过t次操作后,得到的数是否能被11整除.首先需要知道的是,被11整除的性质是”奇偶位的和之差能被11整除”. 然后根据此性质开始模拟操作过程即可原创 2015-08-11 20:47:24 · 349 阅读 · 0 评论 -
【HDOJ 2031】 进制转换
Problem Description输入一个十进制数N,将它转换成R进制数输出。 Input输入数据包含多个测试实例,每个测试实例包含两个整数N(32位整数)和R(210)。 Output为每个测试实例输出转换后的数,每个输出占一行。如果R大于10,则对应的数字规则参考16进制(比如,10用A表示,等等)。原创 2015-01-31 22:33:43 · 504 阅读 · 0 评论 -
【HDOJ 1003】 Max Sum
Problem DescriptionGiven a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5原创 2015-02-22 17:21:44 · 649 阅读 · 0 评论 -
【HDOJ 1000】 A + B Problem
Problem DescriptionCalculate A + B. InputEach line will contain two integers A and B. Process to end of file. OutputFor each case, output A + B in one line.原创 2014-12-12 21:05:53 · 330 阅读 · 0 评论 -
[HDOJ 4520] 小Q系列故事――最佳裁判
题目描述小Q系列故事――最佳裁判解题思路参考代码#include <stdio.h>#include <math.h>const int inf = 0x3f3f3f3f;double arr[25];int main(){ int n,i; while (~scanf("%d",&n) && n){ double max = -1,min = inf,su原创 2015-07-26 17:00:56 · 246 阅读 · 0 评论 -
[HDOJ 4524] 郑厂长系列故事――逃离迷宫
题目描述郑厂长系列故事――逃离迷宫解题思路参考代码#include <stdio.h>int main(){ int T,n; scanf("%d",&T); while (T--){ scanf("%d",&n); bool flag = true; __int64 ans = 0,a,v = 0; whi原创 2015-07-26 17:01:06 · 322 阅读 · 0 评论 -
HDOJ 1002 A + B Problem II //高精度加法
Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow,原创 2014-12-12 20:39:01 · 367 阅读 · 0 评论 -
[HDOJ 4506] 小明系列故事――师兄帮帮忙
题目描述小明系列故事――师兄帮帮忙解题思路参考代码#include <iostream>#include <vector>#include <algorithm>#define MOD 1000000007const int maxn = 10010;typedef long long ll;ll v[maxn];using namespace std;ll quickpow(ll原创 2015-07-26 16:52:56 · 478 阅读 · 0 评论 -
[HDOJ 4550] 卡片游戏
题目描述卡片游戏解题思路参考代码#include<iostream>#include<string>using namespace std;int main(){ int T,i; string ans,s; scanf("%d",&T); while(T--){ cin >> s; ans = s[0]; ch原创 2015-07-26 17:33:59 · 384 阅读 · 0 评论 -
[HDOJ 4505] 小Q系列故事――电梯里的爱情
题目描述小Q系列故事――电梯里的爱情解题思路参考代码#include <iostream>#include <algorithm>#include <vector>using namespace std;int main(){ int c; while (~scanf("%d",&c)){ while (c--){ int n,a;原创 2015-07-26 16:50:50 · 339 阅读 · 0 评论 -
[HDOJ 4551] 生日猜猜猜
题目描述生日猜猜猜解题思路参考代码#include <stdio.h>int day[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};int gcd(int a,int b){ if (a < b) return gcd(b,a); else if (b =原创 2015-07-26 17:30:37 · 375 阅读 · 0 评论 -
[HDOJ 4509] 湫湫系列故事――减肥记II
题目描述湫湫系列故事――减肥记II解题思路参考代码#include <iostream>#include <algorithm>using namespace std;const int maxn = 500010; struct Time{ int start,end;}t[maxn];int tran(int h,int m){return h*60+m;}bool cmp原创 2015-07-26 16:57:38 · 402 阅读 · 0 评论 -
[HDOJ 4508] 湫湫系列故事――减肥记I
题目描述湫湫系列故事――减肥记I解题思路参考代码#include <iostream> #include <algorithm> using namespace std; const int maxn = 100010;int dp[maxn]; int main() { int T; while(~scanf("%d",&T)){原创 2015-07-26 16:56:16 · 275 阅读 · 0 评论 -
[HDOJ 4501] 小明系列故事——买年货
题目描述小明系列故事——买年货解题思路参考代码#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int maxn = 110;struct Node{ int price,score,val;}s[maxn];int dp[maxn][maxn][7];int原创 2015-07-26 17:24:43 · 590 阅读 · 0 评论 -
HDU 4548 美素数 // 素数筛法
题目描述美素数解题思路参考代码#include <stdio.h>#include <string.h>const int maxn = 1000010;bool IsPrime[maxn];int Prime[maxn/2];int ans[maxn];void GetPrime(){ int tot = 0; memset(IsPrime,true,sizeof(Is原创 2015-07-26 17:26:18 · 385 阅读 · 0 评论 -
HDU 5375 Gray code //递推dp
题目描述HDOJ 5375 Gray code解题思路题目大意: 将二进制数转换为格雷码(二进制位上有若干个 ‘?’ , 则该位可为0 或 1) 若格雷码某位上为1,则得到相应位上的分数,求最大分数.转换规则: B (二进制) -> G (格雷码) 1 2 … n B1{B}_{1} B2{B}_{2} … Bn{B}_{n} G1{G}_{1} = B1{B原创 2015-08-11 22:06:45 · 398 阅读 · 0 评论 -
HDU 3068 最长回文 // Manacher
题目描述HDU 3068 最长回文解题思路题目大意: 输出最长回文子串的长度。 Manacher算法传送门 参考代码//**********************************************// Author: @xmzyt1996// Date: 2015-10-26// Name: HDU 3068.cpp//********************原创 2015-10-27 00:05:35 · 500 阅读 · 0 评论