HDU 5742 It's All In The Mind (贪心)】的更多相关文章

题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int gcd(int a,int b) { if(!b) return a; return gcd(b,a%b); } int main() { int t; ci…
It's All In The Mind 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5742 Description Professor Zhang has a number sequence a1,a2,...,an. However, the sequence is not complete and some elements are missing. Fortunately, Professor Zhang remembers some…
It's All In The Mind 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5742 Description Professor Zhang has a number sequence a1,a2,...,an. However, the sequence is not complete and some elements are missing. Fortunately, Professor Zhang remembers some…
Chess Problem Description   Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other chesses on the right adjacent block of the mov…
It's All In The Mind Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 409    Accepted Submission(s): 189 Problem Description Professor Zhang has a number sequence a1,a2,...,an. However, the seque…
It's All In The Mind Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 505    Accepted Submission(s): 225 Problem Description Professor Zhang has a number sequence a1,a2,...,an . However, the sequ…
http://acm.hdu.edu.cn/showproblem.php?pid=5055 题目大意: 给你N位数,每位数是0~9之间.你把这N位数构成一个整数. 要求: 1.必须是奇数 2.整数的前面没有0 3.找到一个最大的整数 如果满足1.2.3条件,就输出这个数,不满足就输出-1. 给个例子 3 1 0 0 这个构成的奇数是001,这个数前面有0,应该输出-1 解题思路: 对给的N个数升序排序. 然后最小的开始找,找到一个奇数,然后把它放在最左边. 然后判断这个数是否,满足要求.满足要…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1052 Problem Description Here is a famous story in Chinese history. "That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king and…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1053 Entropy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7233    Accepted Submission(s): 3047 Problem Description An entropy encoder is a data…
Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11572    Accepted Submission(s): 3239 Problem Description Here is a famous story in Chinese history. "That was about 2…
HDU 5969 最大的位或 题目大意 B君和G君聊天的时候想到了如下的问题. 给定自然数\(l\)和\(r\) ,选取\(2\)个整数\(x,y\)满足\(l <= x <= y <= r\),使得\(x|y\)最大. \(0 <= l <= r <= 10181018\) solution 你看那数据范围,是不是像极了\(TLE\) 又是玄学贪心 异或最大,那么就尽可能让每一位上都是1,按照这个策略贪心即可,注意long long #include<cstdi…
贪心策略 1.使负数为偶数个,然后负数就不用管了 2.0变为1 3.1变为2 4.2变为3 5.若此时操作数剩1,则3+1,否则填个1+1,然后回到5…
以为是贪心,结果不是,2333 贪心最后对自己绝对有利的情况 点我 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> using namespace std; #define MOD 1000000007 const int INF=0…
DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 866    Accepted Submission(s): 250 Problem Description A topological sort or topological ordering of a directed g…
Random Maze Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1669    Accepted Submission(s): 682 Problem Description In the game “A Chinese Ghost Story”, there are many random mazes which have s…
题意:又是中文题... 析:先说一下区间贪心的一个定理,选择不相交的区间:数轴上有n个开区间(ai, bi).选择尽量多的区间,使得这些区间两两不相交,贪心策略是,一定是选bi小的.(想一下为什么). 知道这个的话,这个问题还不so easy!先对每个节目结束的时间排序,然后一个一个的选,保证没有相交,也就是说当前的开始时间一定要是上一个后面或者上一个刚结束当前就开始就OK了. 代码如下: #include <iostream> #include <cstdio> #include…
思路:维护一个递增队列,如果当天的w比队首大,那么我们给收益增加 w - q.top(),这里的意思可以理解为w对总收益的贡献而不是真正获利的具体数额,这样我们就能求出最大收益.注意一下,如果w对收益有贡献,你会发现w入队了两次,这是因为这里的w可能会有两种可能: 1.当做中间价/最终卖出价 2.买入价 所以我们入队两个w,如果w是买入价,那么其中一个w作为中间价势必弹出,另一个w作为买入价:如果w是最终卖出价,那么两个w会一直待在队列里. 计算总数很简单,用map[i]表示以i为中间价还存在多…
Description     A new Semester is coming and students are troubling for selecting courses. Students select their course on the web course system. There are n courses, the ith course is available during the time interval (A i,B i). That means, if you…
Description John is the only priest in his town. October 26th is the John's busiest day in a year because there is an old legend in the town that the couple who get married on that day will be forever blessed by the God of Love. This year N couples p…
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10423    Accepted Submission(s): 4287 Problem Description There is a pile of n wooden sticks. The length and weight of each stick ar…
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 41982    Accepted Submission(s): 13962 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g…
Game Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1376    Accepted Submission(s): 449 Problem Description It is well known that Keima Katsuragi is The Capturing God because of his exceptional…
题目链接 Paths on the tree 来源  2014 多校联合训练第5场 Problem B 题意就是给出m条树上的路径,让你求出可以同时选择的互不相交的路径最大数目. 我们先求出每一条路径(u, v)中u和v的LCA:w,按照路径的w的深度大小deep[w]对所有的路径排序. deep[w]越大,排在越前面. 然后从第一条路径开始一次处理,看c[u]和c[v]是否都没被标记过,如果都没被标记过则我们把这条路径选上,把答案加1. 同时标记以w为根的子树的节点为1,方便后续对c数组的查询…
题目大意: 在给定带权值节点的树上从1开始不回头走到某个底端点后得到所有经过的点的权值后,这些点权值修改为0,到达底部后重新回到1,继续走,问走k次,最多能得到多少权值之和 这其实就是相当于每一次都走权值最大的那一条路径,进行贪心k次 首先先来想想树链剖分的时候的思想: 重儿子表示这个儿子对应的子树的节点数最多,那么每次访问都优先访问重儿子 这道题里面我们进行一下转化,如果当前儿子能走出一条最长的路径,我们就令其为重儿子,那么很容易想到,到达父亲时,如果选择重儿子,那么之前到达 父亲所得的权值一…
算法分析: 这个问题很显然可以转化成一个二分图最佳匹配的问题.把田忌的马放左边,把齐王的马放右边.田忌的马A和齐王的B之间,如果田忌的马胜,则连一条权为200的边:如果平局,则连一条权为0的边:如果输,则连一条权为-200的边. 然而我们知道,二分图的最佳匹配算法的复杂度很高,无法满足N=2000的要求. 我们不妨用贪心思想来分析一下问题.因为田忌掌握有比赛的“主动权”,他总是根据齐王所出的马来分配自己的马,所以这里不妨认为齐王的出马顺序是按马的速度从高到低出的.由这样的假设,我们归纳出如下贪心…
作为杭电的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日子,养家糊口就靠它了,呵呵  但是对于学校财务处的工作人员来说,这一天则是很忙碌的一天,财务处的小胡老师最近就在考虑一个问题:如果每个老师的工资额都知道,最少需要准备多少张人民币,才能在给每位老师发工资的时候都不用老师找零呢?  这里假设老师的工资都是正整数,单位元,人民币一共有100元.50元.10元.5元.2元和1元六种. Input 输入数据包含多个测试实例,每个测试实例的第一行是一个整数n(n<100),表示老师的人数,…
给N个数字(0-9),让你组成一个数. 要求:1.这个数是奇数 2.这个数没有前导0 问这个数最大是多少. 思路&解法: N个数字从大到小排序,将最小的奇数与最后一位交换,把剩下前N-1位从大到小排序.输出.(判断第一位是否为0) 代码: #include <cstdio> #include <iostream> #include <string.h> #include <cstdlib> #include <algorithm> #in…
http://acm.hdu.edu.cn/showproblem.php?pid=4544 优先队列+贪心. #include <cstdio> #include <queue> #include <cstring> #include <iostream> #include <algorithm> #define ll long long #define maxn 1000010 using namespace std; int b[maxn]…
戳我穿越:http://acm.hdu.edu.cn/showproblem.php?pid=1735 对于贪心,二分,枚举等基础一定要掌握的很牢,要一步一个脚印走踏实 这是道贪心的题目,要有贪心的意识. 首先将所有为0的地方统计,因为是求最小的字数,所有最后一行后面的0可以看为空格直接减掉, 因为有m段(一定包括第一行),再减去m*2,最后枚举每行,将至少前两个为0的上一行的最后有多少 的0统计起来排序,再依次减去前m-1个大的,这样就保证了得到的答案是符合条件中最小的 code #inclu…
A - Acperience HDU - 5734 题意: 给你一个加权向量,需要我们找到一个二进制向量和一个比例因子α,使得|W-αB|的平方最小,而B的取值为+1,-1,我们首先可以想到α为输入数据的平均值,考虑到是平方和,然后化简表达式,可以得到一个化简的式子,用n通分,可以做到没有除法,然后分子分母化简到互质. #define _CRT_SECURE_NO_WARNINGS #include<cstdio> #include<cstring> #include<iom…