hdu 5821 (贪心排序) Ball】的更多相关文章

题目:这里 题意:T组数据,两个长度都为n的数组,有m次操作,操作是对a数组而言,每次操作给一个区间范围l,r,可以将这个区间内的数任意交换顺序,问经过m次操作后, 是否可以将a数组变为b数组. 输入a数组的时候不仅记录数本身,还要记录其在b数组中的位置,然后每次操作的时候将这个区间内的数按其记录的位置的从小到大的顺序排列,如果m次后能够 得到b,就行了,不能就No. #include<cstdio> #include<cstring> #include<iostream&g…
Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8984    Accepted Submission(s): 4594 Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球…
Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7941    Accepted Submission(s): 4070 Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球…
n个数,已经有大小关系,现给m个约束,规定a在b之前,剩下的数要尽可能往前移.输出序列 大小关系显然使用拓扑结构,关键在于n个数本身就有大小关系,那么考虑反向建图,优先选择值最大的入度为零的点,这样得到的序列就是从大到小的,最后倒序输出就行了. 写这题的时候头好痛阿肚子好痛阿,再也不想熬夜了,一点效率都没有. /** @Date : 2017-09-29 19:29:12 * @FileName: HDU 4857 拓扑排序 + 优先队列.cpp * @Platform: Windows * @…
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #include <bits/stdc++.h> #define nmax 200000 using namespace std; struct Tree{ int l,r,val; int lazy; int mid(){ return (l+r)>>1; } }; Tree tree[nmax&…
有n个成绩,给出m个分数间的相对大小关系,问是否合法,矛盾,不完全,其中即矛盾即不完全输出矛盾的. 相对大小的关系可以看成是一个指向的条件,如此一来很容易想到拓扑模型进行拓扑排序,每次检查当前入度为0的点个数是否大于1,如大于1则不完全:最终状态检查是否所有点都具有大小关系,遍历过说明有入度.但是由于“=”的存在,要考虑将指向相等数的边全部移到一个数上,故使用并查集预先将相等的点连成块,再进行拓扑排序就行了. /** @Date : 2017-09-22 13:58:31 * @FileName…
题目:传送门. 题意:T组数据,每组给定一个n一个m,在给定两个长度为n的数组a和b,再给定m次操作,每次给定l和r,每次可以把[l,r]的数进行任意调换位置,问能否在转换后使得a数组变成b数组. 题解:用结构体存储a数组,一共两个域,一个是值,一个是下标,这个下标指的是他最后应该在的位置即这个值在b数组中的下标.随后m次操作可以看做是对a数组的lr这个区间进行m次sort,sort是根据下标从小到大排序,这样会使得这个数向他应该在的位置偏移,就是把a数组往b数组上靠,该向左的向左去,该向右的向…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5821 有n个盒子,每个盒子最多装一个球. 现在进行m次操作,每次操作可以将l到r之间盒子的球任意交换. 问进行上述操作后,是否能变成指定的状态. 将颜色相同的球,尽量靠最终状态近的分配.对于每次操作 按最终序号靠近进行排序.最后检查是否一致就行了. 官方题解:假设有4个红球,初始时从左到右标为1,2,3,4.那么肯定存在一种方案,使得最后结束时红球的顺序没有改变,也是1,2,3,4. 那么就可以把同…
Ball 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes numbered 1,2,...,n. Each box can contain at most one ball. You are given the initial configuration of the balls. For 1≤i≤n, if the i-th box is empty the…
Ball 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5821 Description ZZX has a sequence of boxes numbered 1,2,...,n. Each box can contain at most one ball. You are given the initial configuration of the balls. For 1≤i≤n, if the i-th box is empty the…
Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2668    Accepted Submission(s): 562 Problem Description Sample Input 1 a 2 aa bb 3 a ba abc Sample Output Case #1: 25 Case #2: 132…
Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1411    Accepted Submission(s): 239 Problem Description Talented Mr.Tang has n strings consisting of only lower case characters.…
这个题目用贪心来做,关键是怎么贪心最小,那就是排序的问题了. 加入给定两个数a1, b1, a2, b2.那么如果先选1再选2的话,总的耗费就是a1 + a1 * b2 + a2; 如果先选2再选1,总的耗费就是a2 + a2 * b1 + a1.这时比较两个数的大小,发现两边都有a1+a2,所以只是比较a1*b2和a2 * b1的大小. #include <cstdio> #include <cstring> #include <algorithm> using na…
ZZX has a sequence of boxes numbered 1,2,...,n1,2,...,n. Each box can contain at most one ball. You are given the initial configuration of the balls. For 1≤i≤n1≤i≤n, if the ii-th box is empty then a[i]=0a[i]=0, otherwise the i-th box contains exactly…
Physical Examination Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6155 Accepted Submission(s): 1754 Problem Description WANGPENG is a freshman. He is requested to have a physical examination wh…
Ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 461    Accepted Submission(s): 273 Problem Description , otherwise the i-th box contains exactly one ball, the color of which is a[i], a posi…
记录一下每个位置最终到达的位置.然后每次操作排序. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #incl…
Monster Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1383    Accepted Submission(s): 363 Problem Description One day, v11 encounters a group of monsters in a foreast. In order to defend the…
http://acm.hdu.edu.cn/showproblem.php?pid=1199 Color the Ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5135    Accepted Submission(s): 1262 Problem Description There are infinite balls i…
戳我穿越:http://acm.hdu.edu.cn/showproblem.php?pid=1735 对于贪心,二分,枚举等基础一定要掌握的很牢,要一步一个脚印走踏实 这是道贪心的题目,要有贪心的意识. 首先将所有为0的地方统计,因为是求最小的字数,所有最后一行后面的0可以看为空格直接减掉, 因为有m段(一定包括第一行),再减去m*2,最后枚举每行,将至少前两个为0的上一行的最后有多少 的0统计起来排序,再依次减去前m-1个大的,这样就保证了得到的答案是符合条件中最小的 code #inclu…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2037 今年暑假不AC Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 71782    Accepted Submission(s): 38586 Problem Description “今年暑假不AC?”“是的.”“那你干什么呢?”“看…
解题思路:排序后贪心,和fatmouse's  trade 类似 Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5837    Accepted Submission(s): 2692 Problem Description 话说上回讲到海东集团面临内外交困,公司的元老也只剩下XHD夫妇二人了.显然,作为多年拼搏…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2831 题目大意:植物大战僵尸.给定种植植物时间间隔t,以及每个僵尸的到达时间v,生命d.问是否能赢. 解题思路: 按照打完每只Zombie之后剩余时间v-d,从小到大排序. 理由如下: 设打完第i只Zombie的剩余时间为:$Remain(v,d)=V-i*t-D$ 那么本题的目标函数为:$arg\max \limits_{i}\sum Remain(v,d)=V-i*t-D$ 所以,应当尽可能把…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3090 题目大意:一共n段路.每段路每千米都会被抢劫一定数量,可以雇佣武士护卫m千米.问最少被抢劫数量. 解题思路: 题目英文很啰嗦.一开始还以为是n段路可选的,其实是都要走完. 那么直接按照抢劫数量从大到小排序.护卫即可.雇佣兵跑了之后,直接扣. 特判n=0时,ans=0. #include "cstdio" #include "algorithm" using na…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2277 Change the ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 694    Accepted Submission(s): 272 Problem Description Garfield has three pile…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1872 稳定排序 Description 大家都知道,快速排序是不稳定的排序方法.如果对于数组中出现的任意a[i],a[j](i<j),其中a[i]==a[j],在进行排序以后a[i]一定出现在a[j]之前,则认为该排序是稳定的. 某高校招生办得到一份成绩列表,上面记录了考生名字和考生成绩.并且对其使用了某排序算法按成绩进行递减排序.现在请你判断一下该排序算法是否正确,如果正确的话,则判断该排序算法是…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5638 题意: 给你一个DAG图,删除k条边,使得能个得到字典序尽可能小的拓扑排序 题解: 把拓扑排序的算法稍微改一下,如果某个顶点的入度小于k也把它加到优先队列里面去. k减小后队列里面会有些点不满足<=k,直接踢出来就好了. 代码: #include<iostream> #include<cstring> #include<cstdio> #include<…
题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3175    Accepted Submission(s): 1457 Problem Description Tom owns a company and he i…
Steal the Treasure Time Limit: 10000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 775    Accepted Submission(s): 213 Problem Description The alliance of thieves decides to steal the treasure from country A.…
B - 贪心 基础 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse contai…