hdu 1698
HDUOJ训练题

HDUOJ训练题OJ输入输出训练:HDOJ 1089 ~HDOJ 1096一、C语言基础练习1001 计算两点间的距离HDOJ 2001 1002 第几天?HDOJ 2005 1003 平方和与立方和HDOJ 2007 1004 水仙花数HDOJ 2010 1005 素数判定HDOJ 2012 1006 数列有序!HDOJ 2019 1007 发工资咯:)HDOJ 2021 1008 海选女主角HDOJ 2022 1009 求平均成绩HDOJ 2023 1010 汉字统计HDOJ 2030 1011 进制转换HDOJ 2031 1012 杨辉三角HDOJ 2032 1013 人见人爱A+B HDOJ 2033 1014 人见人爱A-B HDOJ 2034 1015 亲和数HDOJ 2040 1016 Sum Problem HDOJ 1001 1017 A + B Problem II HDOJ 1002 1018 Let the Balloon Rise HDOJ 1004 1019 Elevator HDOJ 1008 1020 FatMouse' Trade HDOJ 1009 1021 As Easy As A+B HDOJ 1040 1022 The Hardest Problem Ever HDOJ 1048 1023 Climbing Worm HDOJ 1049 1024 Text Reverse HDOJ 1062 1025 An Easy Task HDOJ 1076 1026 What Is Your Grade? HDOJ 1084二、简单数学题1001 最小公倍数HDOJ 1108 1002 Least Common Multiple HDOJ 1019 1003 人见人爱A^B HDOJ 0235 1004 Rightmost Digit HDOJ 1061 1005 Fibonacci Again HDOJ 1021 1006 Number Sequence HDOJ 1005 1007 The area HDOJ 1071 1008 吃糖果HDOJ 1205 1009 Sky数HDOJ 2097 1010 Box of Bricks HDOJ 2088 1011 简易版之最短距离HDOJ 20831012 Fibbonacci Number HDOJ 20701013 Coin Change HDOJ 20691014 A + B Again HDOJ 20571015 Lowest Common Multiple Plus HDOJ 20281016 Can you solve this equation? HDOJ 21991017 Strange fuction HDOJ 28991018 Pseudoprime numbers HDOJ 19051019 Delta-wave HDOJ 10301020 月之数HDOJ 25021021 又见GCD HDOJ 25041022 找新朋友HDOJ 12861023 七夕节HDOJ 12151024 完数HDOJ 1406三、递推求解1001 超级楼梯HDOJ 20411002 不容易系列之二HDOJ 20421003 一只小蜜蜂... HDOJ 20441004 不容易系列之(3)——LELE的RPG难题HDOJ 20451005 骨牌铺方格HDOJ 20461006 折线分割平面HDOJ 20501007 母牛的故事HDOJ 20181008 下沙的沙子有几粒?HDOJ 12671009 自共轭Ferrers图HDOJ 12461010 汉诺塔II HDOJ 12071011 悼念512汶川大地震遇难同胞——重建希望小学HDOJ 2190 1012 Children’s Queue HDOJ 12971013 Tiling_easy version HDOJ 25011014 统计问题HDOJ 25631015 Buy the Ticket HDOJ 11331016 Game of Connections HDOJ 11341017 Computer Transformation HDOJ 10411018 Children’s Queue HDOJ 12971019 The Number of Paths HDOJ 12931020 "下沙野骆驼"ACM夏令营HDOJ 129四、简单典型DP1001 数塔HDOJ 20841002 Super Jumping! Jumping! Jumping! HDOJ 10871003 免费馅饼HDOJ 11761004 Common Subsequence HDOJ 11591005 搬寝室HDOJ 14211006 Humble Numbers HDOJ 10581007 Max Sum HDOJ 10031008 Max Sum Plus Plus HDOJ 10241009 FatMouse's Speed HDOJ 11601010 Bone Collector HDOJ 26021011 Piggy-Bank HDOJ 11141012 I NEED A OFFER! HDOJ 12031013 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活HDOJ 2191 1014 Coins HDOJ 2844五、简单博弈1001 Brave Game HDOJ 18461002 Good Luck in CET-4 Everybody! HDOJ 18471003 Fibonacci again and again HDOJ 18481004 Rabbit and Grass HDOJ 18491005 Being a Good Boy in Spring Festival HDOJ 18501006 kiki's game HDOJ 21471007 Public Sale HDOJ 21491008 悼念512汶川大地震遇难同胞——选拔志愿者HDOJ 2188 1009 丑数游戏1010 YLF's Game六、半程测试1001 CD HDOJ 37631002 Alaska HDOJ 37641003 Celebrity Split HDOJ 37651004 Knight's Trip HDOJ 37661005 Paintball HDOJ 37671006 Shopping HDOJ 37681007 Stack Machine HDOJ 37691008 Ideas HDOJ 37701009 HST HDOJ 37711010 Tunnelling the Earth H DOJ 3772七、母函数1001 Ignatius and the Princess III HDOJ 10281002 Square Coins HDOJ 13981003 Holding Bin-Laden Captive! HDOJ 10851004 Big Event in HDU HDOJ 11711005 Fruit HDOJ 21521006 The Balance HDOJ 1709八、并查集1001 How Many T ables HDOJ 1213 1002 小希的迷宫HDOJ 1272 1003 Is It A Tree? HDOJ 1325 1004 More is better HDOJ 1856 1005 Constructing Roads HDOJ 1102 1006 畅通工程HDOJ 1232 1007 还是畅通工程HDOJ 1233 1008 畅通工程HDOJ 1863 1009 畅通工程再续HDOJ 1875 1010 继续畅通工程HDOJ 1879 共26 + 24 + 20 + 14 + 10 + 6 + 10 = 110 题。
HDU100题简要题解(2060~2069)

HDU100题简要题解(2060~2069)这⼗题感觉是100题内相对较为⿇烦的,好多数学题,有点搞我⼼态...歪⽐巴⼘HDU2060 SnookerProblem Descriptionbackground:Philip likes to play the QQ game of Snooker when he wants a relax, though he was just a little vegetable-bird. Maybe you hadn't played that game yet, no matter, I'll introduce the rule for you first.There are 21 object balls on board, including 15 red balls and 6 color balls: yellow, green, brown, blue, pink, black.The player should use a white main ball to make the object balls roll into the hole, the sum of the ball's fixed value he made in the hole is the player's score. The player should firstly made a red ball into the hole, after that he gains red-ball's value(1 points), then he gets the chance to make a color ball, then alternately. The color ball should be took out until all the red-ball are in the hole. In other word, if there are only color balls left on board, the player should hit the object balls in this order: yellow(2 point), green(3 point), brown(4 point), blue(5 point), pink(6 point), black(7 point), after the ball being hit into the hole, they are not get out of the hole, after no ball left on board, the game ends, the player who hasthe higher score wins the game. PS: red object balls never get out of the hole.I just illustrate the rules that maybe used, if you want to contact more details, visit afterthe contest.for example, if there are 12 red balls on board(if there are still red ball left on board, it can be sure that all the colorballs must be on board either). So suppose Philp can continuesly hit the ball into the hole, he can get the maximun score is12 * 1 (12 red-ball in one shoot) + 7 * 12(after hit a red ball, a black ball which was the most valuable ball should be the target) +2 +3 +4 +5 +6 + 7(when no red ball left, make all the color ball in hole).Now, your task is to judge whether Philip should make the decision to give up when telling you the condition on board(How many object balls still left not in the hole and the other player's score). If Philp still gets the chance to win, just print "Yes", otherwise print "No". (PS: if the max score he could get on board add his current score is equal to the opponent's current score, still output "Yes")InputThe first line contains a numble N indicating the total conditions. Then followed by N lines, each line is made of three integers: Ball_Left P_Score O_Score represeting the ball number left on board, Philp's current score, and the opponent's current score.All the input value are in 32 bit integer value range.OutputYou should caculate the max score left Philp can gain, and judge whether he has the possiblity to win.Sample Input212 1 11 30 39Sample OutputYesNo看到题⽬,脸上笑嘻嘻,⼼⾥......硬着头⽪看完了,发现是道⽔题:)分两种情况,加起来:1、⼤于六个球也就是有红球的情况,每打⼀个红球就紧接着打⼀个⿊球,打完红球再把其他颜⾊的打进去2、少于六个球也就是⽆红球的情况,假装剩下的都是相对较⼤的球#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>using namespace std;int n, x, num1, num2;int main() {while (scanf("%d", &n) != EOF) {while (n--) {scanf("%d%d%d", &x, &num1, &num2);if (x > 6)num1 += (x - 6) * 8 + 27;else {int cnt = 7;while (x--) {num1 += cnt;cnt--;}}if (num1 >= num2) printf("Yes\n");else printf("No\n");}}return 0;}HDU2061 Treasure the new start, freshmen!Problem Descriptionbackground:A new semester comes , and the HDU also meets its 50th birthday. No matter what's your major, the only thing I want to tell youis:"Treasure the college life and seize the time." Most people thought that the college life should be colorful, less presure.But in actual, the college life is also busy and rough. If you want to master the knowledge learned from the book, a great deal of leisure time should be spend on individual study and practise, especially on the latter one. I think the every one of you should take the learning attitude just as you have in senior school."No pain, No Gain", HDU also has scholarship, who can win it? That's mainly rely on the GPA(grade-point average) of the student had got. Now, I gonna tell you the rule, and your task is to program to caculate the GPA.If there are K(K > 0) courses, the i-th course has the credit Ci, your score Si, then the result GPA isGPA = (C1 * S1 + C2 * S2 +……+Ci * Si……) / (C1 + C2 + ……+ Ci……) (1 <= i <= K, Ci != 0)If there is a 0 <= Si < 60, The GPA is always not existed.InputThe first number N indicate that there are N test cases(N <= 50). In each case, there is a number K (the total courses number), then K lines followed, each line would obey the format: Course-Name (Length <= 30) , Credits(<= 10), Score(<= 100).Notice: There is no blank in the Course Name. All the Inputs are legalOutputOutput the GPA of each case as discribed above, if the GPA is not existed, ouput:"Sorry!", else just output the GPA value which is rounded to the 2 digits after the decimal point. There is a blank line between two test cases.Sample Input23Algorithm 3 97DataStruct 3 90softwareProject 4 852Database 4 59English 4 81Sample Output90.10Sorry!头⼤,看完发现⼜是⼀道⽔题,题意的精华在于其中的公式:GPA = (C1 * S1 + C2 * S2 +……+Ci * Si……) / (C1 + C2 + ……+ Ci……) (1 <= i <= K, Ci != 0)然后⽤这个算,并且⽤⼀个flag记录是否存在有不及格科⽬的情况#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <algorithm>using namespace std;int n, m;double a[101], b[101];int main() {while (scanf("%d", &n) != EOF) {while (n--) {scanf("%d", &m);double sum = 0;double num = 0;int flag = 0;for (int i = 1; i <= m; i++) {string s;cin >> s;scanf("%lf%lf", &a[i], &b[i]);if (b[i] < 60) flag = 1;sum += a[i] * b[i];num += a[i];}if (flag == 1) cout << "Sorry!" << endl;else {double ans = (sum + 0.0) / num;printf("%.2lf\n", ans);}if (n) cout << endl;}}return 0;}HDU2062 Subset sequenceProblem DescriptionConsider the aggregate An= { 1, 2, …, n }. For example, A1={1}, A3={1,2,3}. A subset sequence is defined as a array of a non-empty subset. Sort all the subset sequece of An in lexicography order. Your task is to find the m-th one.InputThe input contains several test cases. Each test case consists of two numbers n and m ( 0< n<= 20, 0< m<= the total number of the subset sequence of An ).OutputFor each test case, you should output the m-th subset sequence of An in one line.Sample Input1 12 12 22 32 43 10Sample Output111 222 12 3 1⼈傻了,康了题解才解决这题,卡这题上了⼀上午...这题我感觉算是这100题⾥思维含量最⾼的⼏个了,反正我是傻了(因为菜借这题终于明⽩了三元运算符,⾼中的时候看学弟⽤过,⼀脸懵逼也没想着去学,终于知道是个啥东西了(求gcd的时候还挺⽅便的,直接⼀⾏解决)题⽬⼤意:考虑⼀个集合 An = { 1, 2, ..., n}。
hdu前缀和与差分题目

hdu前缀和与差分题目【原创版】目录1.概述 hdu 前缀和差分题目2.hdu 前缀和差分题目的解题思路3.hdu 前缀和差分题目的实例解析正文一、概述 hdu 前缀和差分题目在编程竞赛中,我们经常会遇到一些涉及数组和前缀和的问题。
而hdu 前缀和差分题目是这类问题中的一种。
它要求我们根据给定的数组,计算前缀和,并根据前缀和的差分求解一些问题。
这类题目涉及到的知识点主要有前缀和的计算方法,以及如何利用前缀和的差分快速求解问题。
二、hdu 前缀和差分题目的解题思路解决这类问题的一般思路如下:1.首先,我们需要计算数组的前缀和。
前缀和的计算方法有多种,如直接求和、循环求和、利用等差数列求和公式等。
在实际操作中,我们可以根据题目的特点和要求,选择合适的计算方法。
2.其次,我们需要根据前缀和的差分求解问题。
这通常涉及到一些基本的算法,如二分查找、哈希表等。
对于一些复杂的问题,我们还需要结合题目的具体要求,设计合适的算法。
三、hdu 前缀和差分题目的实例解析以一个具体的题目为例,题目描述如下:给定一个长度为 n 的整数数组 a,要求我们计算前缀和数组 s,并根据 s 的差分数组 t 求解一些问题。
其中,前缀和数组 s 满足 s[i] =a[0] + a[1] +...+ a[i],而差分数组 t 满足 t[i] = s[i+1] - s[i]。
针对这个题目,我们可以按照以下步骤进行求解:1.计算前缀和数组 s。
我们可以使用循环求和的方法,时间复杂度为O(n)。
2.计算差分数组 t。
我们可以通过 s 数组求解,时间复杂度为 O(n)。
3.根据差分数组 t 求解问题。
这涉及到一些具体的问题,如求最大值、最小值等。
我们可以根据问题的具体要求,设计合适的算法。
综上所述,解决 hdu 前缀和差分题目,我们需要掌握前缀和的计算方法和差分的求解方法,同时结合题目的具体要求,设计合适的算法。
杭电ACM试题详细分类,杭电oj详细分类,hdu详细分类,详细,ACM.doc

杭电ACM试题分类枚举1002 10041013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 10391042 10471048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 10841088 11061107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 117711971200 1201 1202 1205 1209 1212(大数取模)1216 (链表)1218 1219 12251228 12291230 1234 1235 1236 1237 1239 1250 1256 1259 1262 1263 1265 12661276 1279 1282 1283 1287 1296 1302 1303 1304 1305 1306 1309 1311 1314搜索,递归求解1010 1016 1026 1043(双广)1044 (BFS+DFS) 1045 1067 1072 1104 1175 1180 11951208 1226 1238 1240 1241 1242 1258 1271 1312 1317动态规划1003 1024 1025 1028 1051 1058 1059 1069 1074 1078 1080 1081 1085 1087 1114 1158 1159 1160 1171 1176 1181 1203 1224 1227 1231 1244 1248 1253 1254 1283 1300数学,递推,规律1005 1006 1012 1014 1018 1019 1021 1023 1027 1030 1032 1038 1041 1046 1059 1060 1061 1065 1066 1071(微积分)1097 1098 1099 1100 1108 1110 1112 1124 1130 1131 1132 1134 1141 1143 1152 1155(物理题)1163 1165 1178 1194 1196(lowbit) 1210 1214 1200 1221 1223 1249 1261 1267 1273 1290 1291 1292 1294 1297 1313 1316数论1164 1211 1215 1222 1286 1299计算几何1086 1115 1147贪心1009 1052 1055 1257 并查集11981213 1232 1272线段树,离散化11991255图论最短路相关的问题1142 1162 1217 1301二分图问题1054 1068 1150 1151 1281其他1053 (huffman) 1102(MST) 1116 (欧拉回路)1233(MST) 1269 (强连通)数据结构1103 (堆+模拟)1166 (数状树组)1247 1251 1285 (Topol) 1298以下是详细介绍1002简单的大数1003 DP经典问题,最大连续子段和1004简单题1005找规律(循环点)1007经典问题,最近点对问题,用分治1008简单题1010搜索题,剪枝很关1009贪心1012简单题1013简单题(有个小陷阱)1014简单题1015可以看作搜索题吧1016经典的搜索1017简单数学题1018简单数学题1019简单数学题1020简单的字符串处理找规律的数学题数据结构的题(栈的应用)特殊的数(Catalan Number)经典DP,最大M 子段和经典DP,最长递增子序列(要用NLogN的方法过)搜索数学题(或用STL)经典问题,整数拆分,用母函数做简单题(一般方法容易超时)简单题,可用模拟过简单题简单题模拟题Candy Sharing Game模拟题简单题简单题,不是一般的简单简单题字符串处理简单题,排序简单题,用大数大数经典搜索题,八数码问题稍微有点麻烦的搜索题搜索题,可用匹配做简单题简单的大数简单字符串处理简单题贪心经典贪心,也可以用DP贪心贪心,关于Huffman编码二分匹配二分匹配简单题模拟题经典问题,丑数,DP经典问题,可以用母函数或DP (不针对题目优化都会超时)数学题数学题简单字符串处理模拟大数简单题1065简单题1066数学题,找规律1068经典二分匹配1069经典DP1070简单题1071简单数学题1072搜索1073字符串处理1074 DP1075字典树1076简单题1078DP1079博弈(DP)1080DP 1081经典DP1082简单题1083二分匹配1084简单题1085母函数1086简单几何题1087简单DP1088字符串处理1089~1096 (练习输入输出的8个题目)1097简单数学题1098数学题,注意找规律1099数学HrH1500DP1501DP1502DP or记忆化1503DP1504模拟1505DP1506DP15072分匹配1508记忆化容易点1509模拟1510 DP1511搜索可以过1512左偏树1513DP1514DP1515DFS1516DP1517博奕搜索DP (不确定)树状DP 数学题稳定婚姻DP 博弈博弈Maxflow博弈2分匹配简单题最大团差分约束Maxflow入门题KM Or > 小费用流差分约束差分约束博弈模拟加置换群的理论CODE可以短些,其实没必要。
hdu1847GoodLucki...

hdu1847GoodLucki...Good Luck in CET-4 Everybody!Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5901 Accepted Submission(s): 3811 Problem Description 大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都没工夫练习了,反正我知道的Kiki和Cici都是如此,。
当然,作为在考场浸润了十几载的当代大学生,Kiki和Cici更懂得考前的放松,所谓“张弛有道”就是这个意思。
这不,Kiki和Cici在每天晚上休息之前都要玩一会儿扑克牌以放松神经。
“升级”?“双扣”?“红五”?还是“斗地主”?当然都不是!那多俗啊~作为计算机学院的学生,Kiki和Cici打牌的时候可没忘记专业,她们打牌的规则是这样的:1、总共n张牌;2、双方轮流抓牌;3、每人每次抓牌的个数只能是2的幂次(即:1,2,4,8,16…)4、抓完牌,胜负结果也出来了:最后抓完牌的人为胜者;假设Kiki和Cici都是足够聪明(其实不用假设,哪有不聪明的学生~),并且每次都是Kiki先抓牌,请问谁能赢呢?当然,打牌无论谁赢都问题不大,重要的是马上到来的CET-4能有好的状态,电脑资料《hdu 1847 Good Luck in CET4 Everybody! 巴什博弈??我分不太清啦,水之~》(https://www.)。
Good luck in CET-4 everybody!Input 输入数据包含多个测试用例,每个测试用例占一行,包含一个整数n(1<=n<=1000)。
Output 如果Kiki能赢的话,请输出“Kiki”,否则请输出“Cici”,每个实例的输出占一行。
2023杭电多校4题解

2023杭电多校4题解【最新版】目录1.2023 杭电多校 4 题解概述2.第一题:编写一个计算两个日期之间相隔天数的程序3.第二题:编写一个检查字符串是否为回文字符串的程序4.第三题:编写一个求解数组中两个数之和等于目标值的程序5.第四题:编写一个判断两个矩阵是否相等的程序6.总结与建议正文一、2023 杭电多校 4 题解概述本文将介绍 2023 年杭州电子科技大学多校联合编程竞赛的第四题解。
题目包括四个编程题目,分别涉及到日期计算、字符串处理、数组操作和矩阵操作。
本文将逐一解析每个题目的解法。
二、第一题:编写一个计算两个日期之间相隔天数的程序这道题目要求编写一个程序,输入两个日期字符串,输出它们之间相隔的天数。
需要注意的是,日期的格式为 "yyyy-MM-dd",且要求能处理跨年和跨月的情况。
我们可以使用 Python 的 datetime 库来处理日期对象,通过计算两个日期对象之间的差值来得出它们之间相隔的天数。
三、第二题:编写一个检查字符串是否为回文字符串的程序这道题目要求编写一个程序,输入一个字符串,输出该字符串是否为回文字符串。
回文字符串是指正序和倒序都相同的字符串,例如"abcdcba" 和 "level" 都是回文字符串。
我们可以使用双指针法,分别从字符串的两端向中间遍历,如果遇到不相等的字符,则说明该字符串不是回文字符串。
四、第三题:编写一个求解数组中两个数之和等于目标值的程序这道题目要求编写一个程序,输入一个整数数组、一个目标值和一个整数 k,输出数组中两个数之和等于目标值的那 k 对数。
我们可以使用哈希表来存储数组中的元素及其对应的索引,遍历数组,对于每个元素,如果哈希表中存在与其对应的元素,则输出这两对数;否则,将该元素及其索引存入哈希表。
五、第四题:编写一个判断两个矩阵是否相等的程序这道题目要求编写一个程序,输入两个二维数组,输出它们是否表示同一个矩阵。
线段树专题题目

线段树专题题目:覆盖的面积(hdu -- 1255)Problem Description给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积.Input输入数据的第一行是一个正整数T(1<=T<=100),代表测试数据的数量.每个测试数据的第一行是一个正整数N(1<=N<=1000),代表矩形的数量,然后是N行数据,每一行包含四个浮点数,代表平面上的一个矩形的左上角坐标和右下角坐标,矩形的上下边和X轴平行,左右边和Y轴平行.坐标的范围从0到100000.注意:本题的输入数据较多,推荐使用scanf读入数据.Output对于每组测试数据,请计算出被这些矩形覆盖过至少两次的区域的面积.结果保留两位小数.Sample Input251 1 4 21 3 3 72 1.5 5 4.53.5 1.25 7.5 46 3 10 730 0 1 11 02 12 03 1Sample Output7.630.00Minimum Inversion Number(hdu-1394) The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai > aj.For a given sequence of numbers a1, a2, ..., an, if we move the first m >= 0 numbers to the end of the seqence, we will obtain another sequence. There are totally n such sequences as the following:a1, a2, ..., an-1, an (where m = 0 - the initial seqence)a2, a3, ..., an, a1 (where m = 1)a3, a4, ..., an, a1, a2 (where m = 2)...an, a1, a2, ..., an-1 (where m = n-1)You are asked to write a program to find the minimum inversion number out of the above sequences.InputThe input consists of a number of test cases. Each case consists of two lines: the first line contains a positive integer n (n <= 5000); the next line contains a permutation of the n integers from 0 ton-1.OutputFor each case, output the minimum inversion number on a single line.Sample Input101 3 6 9 0 8 5 7 4 2Sample Output16Tunnel Warfare(hdu -- 1540)Problem DescriptionDuring the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a line. Except the two at the ends, every village was directly connected with two neighboring ones.Frequently the invaders launched attack on some of the villages and destroyed the parts of tunnels in them. The Eighth Route Army commanders requested the latest connection state of the tunnels and villages. If some villages are severely isolated, restoration of connection must be done immediately!InputThe first line of the input contains two positive integers n and m (n, m ≤ 50,000) indicating the number of villages and events. Each of the next m lines describes an event. There are three different events described in different format shown below:D x: The x-th village was destroyed.Q x: The Army commands requested the number of villages that x-th village was directly or indirectly connected with including itself.R: The village destroyed last was rebuilt.OutputOutput the answer to each of the Ar my commanders‟ request in order on a separate line. Sample Input7 9D 3D 6D 5Q 4Q 5RQ 4RQ 4Sample Output124Atlantis(hdu--1542)InputThe input file consists of several test cases. Each test case starts with a line containing a single integer n (1<=n<=100) of available maps. The n following lines describe one map each. Each of these lines contains four numbers x1;y1;x2;y2(0<=x1<x2<=100000;0<=y1<y2<=100000), not necessarily integers. The values (x1; y1) and (x2;y2) are the coordinates of the top-left resp. bottom-right corner of the mapped area.The input file is terminated by a line containing a single 0. Don‟t process it.OutputFor each test case, your program should output one section. The first line of each section must be “Test case #k”, where k is the number of the test case (starting with 1). The second one must be “Total explored area: a”, where a is the total explored area (i.e. the area of the union of all rectangles in this test case), printed exact to two digits to the right of the decimal point.Output a blank line after each test case.Sample Input210 10 20 2015 15 25 25.5Sample OutputTest case #1Total explored area: 180.00Just a Hook(hdu--1698)InputThe input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases.For each case, the first line contains an integer N, 1<=N<=100,000, which is the number of the sticks of Pudge‟s meat hook and the second line contains an integer Q, 0<=Q<=100,000, which is the number of the operations.Next Q lines, each line contains three integers X, Y, 1<=X<=Y<=N, Z, 1<=Z<=3, which defines an operation: change the sticks numbered from X to Y into the metal kind Z, where Z=1 represents the cupreous kind, Z=2 represents the silver kind and Z=3 represents the golden kind.OutputFor each case, print a number in a line representing the total value of the hook after the operations. Use the format in the example.Sample Input11021 5 25 9 3Sample OutputCase 1: The total value of the hook is 24.Luck and Love(hdu -- 1823)Problem Description由于人数太多,Wiskey实在忙不过来,就把统计的事情全交给了枫冰叶子,自己跑回家休息去了。
各大OJ题目归类

各大OJ题目归类—————————–最优化问题————————————- ———————-动态规划SOJ1162 I-KeyboardSOJ2096 Maximum SubmatrixSOJ2111 littleken bgSOJ2505 The County FairSOJ2818 QQ音速SOJ2469 Exploring PyramidsSOJ1833 Base NumbersSOJ2009 Zeros and OnesSOJ2032 The Lost HouseSOJ2289 A decorative fenceSOJ2089 lykooSOJ2440 The days in fzkSOJ2718 BookshelfSOJ2722 Treats for the Cows(二维状态,0维决策)SOJ2726 Deck of CardsSOJ2729 Space ElevatorSOJ2730 Lazy CowsSOJ2702 AlannaSOJ2713 Cut the SequenceSOJ2768 BombSOJ2779 Find the max (I) (最大M子段和问题)SOJ2796 Letter Deletion(DP基础题,最长公共子序列问题) SOJ2800 三角形SOJ2804 Longest Ordered Subsequence (II)SOJ2896 Alphacode (动态规划简单题)SOJ2930 积木城堡SOJ3037 Painting the ballsSOJ3104 Game(注意大数运算,高精度)SOJ3264 Evil GameSOJ3300 Stockholm Coins(背包问题)SOJ3360 Buying Hay(背包问题)SOJ3531 Number Pyramids(背包问题)—————-状态DPSOJ2089 lykooSOJ2819 AderSOJ2842 The TSP problemSOJ3025 Artillery(状态DP)SOJ3088 windy’s cake VIIISOJ3259 Counting numbersSOJ3262 Square Fields(二分+状态DP)SOJ3371 Mixed Up Cows—————最优化之排序(思考两个元素之间的先后关系,以此得出一个二元比较关系,并验证此关系可传递,反对称,进而排序)SOJ2509 The Milk QueueSOJ2547 cardsSOJ2850 Protecting the FlowersSOJ2957 Setting ProblemsSOJ3167 ComputerSOJ3331 Cards(2547加强版)SOJ3327 Dahema’s Computer(通过此题学会排序)—————–最优化之必要条件枚举(思考最优解所具有的性质,得出最优解的一个强必要条件,在此基础上枚举)SOJ3317 FGJ’s PlaneSOJ3429 Food portion sizes——————————–贪心—————————————SOJ1078 BlueEyes’ ScheduleSOJ1203 Pass-MurailleSOJ1673 Gone FishingSOJ2645 Buy One Get One FreeSOJ2701 In a CycleSOJ2876 Antimonotonicity(经典模型O(n)算法)SOJ3343 Tower——————————–搜索—————————————SOJ1626 squareSOJ2061 8 puzzleSOJ2485 SudokuSOJ1045 SticksSOJ2736 FliptileSOJ2771 Collecting StonesSOJ2715 Maze BreakSOJ2829 binary strings(双向BFS)SOJ3330 Windy’s Matrix(BFS)——————————–DFA—————————————-—————状态矩阵+DFA:SOJ1826 Number SequenceSOJ2552 Number of TilingsSOJ2919 Matrix Power Series (学习矩阵的快速乘法从此开始)SOJ2920 Magic BeanSOJ3021 Quad TilingSOJ3046 Odd Loving BakersSOJ3176 E-stringSOJ3246 Tiling a Grid With DominoesSOJ3323 K-Satisfied NumbersSOJ3337 Wqb’s Word—————-DFA+DPSOJ1112 Repeatless Numbers(DFA+二分)SOJ2913 Number SubstringSOJ2826 Apocalypse SomedaySOJ3030 DNA Sequence(AC自动机+矩阵二分)SOJ3128 windy和水星—水星数学家1SOJ3182 Windy numbers———————————图论———————————————————–最短路+最小生成树+强连通SOJ2832 Mars city(强连通分支,算法多多)SOJ2198 HighwaysSOJ3427 Dark roads(最小生成树,kruskal:快排+并查集)SOJ3346 Best Spot(最短路,N^3放心的写)SOJ3013 tree(树的最大—最小划分问题,二分+贪心,勉强算在图论里面吧。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Just a Hook
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16563 Accepted Submission(s): 8234
Problem Description
In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length.
Now Pudge wants to do some operations on the hook.
Let us number the consecutive metallic sticks of the hook from 1 to N. For each operation, Pudge can change the consecutive metallic sticks, numbered from X to Y, into cupreous sticks, silver sticks or golden sticks.
The total value of the hook is calculated as the sum of values of N metallic sticks. More precisely, the value for each kind of stick is calculated as follows:
For each cupreous stick, the value is 1.
For each silver stick, the value is 2.
For each golden stick, the value is 3.
Pudge wants to know the total value of the hook after performing the operations.
You may consider the original hook is made up of cupreous sticks.
Input
The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases.
For each case, the first line contains an integer N, 1<=N<=100,000, which is the number of the sticks of Pudge’s meat hook and the second line contains an integer Q, 0<=Q<=100,000, which is the number of the operations.
Next Q lines, each line contains three integers X, Y, 1<=X<=Y<=N, Z, 1<=Z<=3, which defines an operation: change the sticks numbered from X to Y into the metal kind Z, where Z=1 represents the cupreous kind, Z=2 represents the silver kind and Z=3 represents the golden kind.
Output
For each case, print a number in a line representing the total value of the hook after the operations. Use the format in the example.
Sample Input
1 10
2 1 5 2 5 9 3
Sample Output
Case 1: The total value of the hook is 24.
Source
2008 “Sunline Cup” National Invitational Contest
Recommend
wangye
AC代码:
#include<iostream>
using namespace std;
struct Node{
int left,right;
int s;
}a[400010];
void built(int cur,int x,int y){
a[cur].left=x;
a[cur].right=y;
a[cur].s=1;
if(x<y){
int mid=(x+y)>>1;
built(cur<<1,x,mid);
built(cur<<1 | 1,mid+1,y);
}
}
void insert(int val,int cur,int x,int y){
if(a[cur].left==x && a[cur].right==y){
a[cur].s=val;
return ;
}
if(a[cur].left==a[cur].right){
a[cur].s=val;
return ;
}
if(a[cur].s){
a[cur<<1].s=a[cur<<1 | 1].s=a[cur].s;
a[cur].s=0;
}
int mid=(a[cur].right+a[cur].left)>>1;
if(y<=mid)
insert(val,cur<<1,x,y);
else if(x>mid)
insert(val,cur<<1 |1,x,y);
else{
insert(val,cur<<1,x,mid);
insert(val,cur<<1 | 1,mid+1,y);
}
}
int sum(int cur,int x,int y){
if(a[cur].s){
//cout<<a[cur].s<<' '<<a[cur].left<<' '<<a[cur].right<<endl;
return (1+a[cur].right-a[cur].left)*a[cur].s;
}
int mid=(x+y)>>1;
return sum(cur<<1,x,mid)+sum(cur<<1 |1,mid+1,y);
}
int main(){
int T; cin>>T;
for(int j=1;j<=T;j++){
int n; cin>>n;
built(1,1,n);
int t; cin>>t;
for(int i=0;i<t;i++){
int x,y,val;
cin>>x>>y>>val;
insert(val,1,x,y);
}
cout<<"Case "<<j<<": The total value of the hook is "<<sum(1,1,n)<<'.'<<endl;
}
return 0;
}。