CF Soldier and Badges (贪心)】的更多相关文章

Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which show…
原题链接:http://codeforces.com/problemset/problem/546/B 原题描述: Soldier and Badges Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can b…
题目传送门 /* 题意:问最少增加多少值使变成递增序列 贪心:排序后,每一个值改为前一个值+1,有可能a[i-1] = a[i] + 1,所以要 >= */ #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ; const int INF = 0x3f3f3f3f; int a[MAXN]; int main(vo…
CF546B Soldier and Badges 简单的贪心qwq 排个序,如果当前数与之前的数相重,已经用过,则加到一个之前没有用过的数 #include<cstdio> #include<algorithm> using namespace std; int n,ans,a[3005]; int main() { scanf("%d",&n); for (int i=0; i<n; i++) scanf("%d",&…
B. Soldier and Badges Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/546/problem/B Description Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how…
B. Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has acoolness factor, which sh…
CF546B Soldier and Badges 题意翻译 给 n 个数,每次操作可以将一个数 +1,要使这 n 个数都不相同, 求最少要加多少? \(1 \le n \le 3000\) 感谢@凉凉 提供的翻译 题目描述 Colonel has \(n\) badges. He wants to give one badge to every of his \(n\) soldiers. Each badge has a coolness factor, which shows how mu…
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard output Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner r…
Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin. For every pair of soldiers one o…
Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness…
题目链接: 传送门 Lawnmower time limit per test:2 second     memory limit per test:256 megabytes Description You have a garden consisting entirely of grass and weeds. Your garden is described by an n × m grid, with rows numbered 1 to n from top to bottom, an…
Soldier and Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are…
Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots…
题面: 传送门 思路: 一眼看得,这是贪心[雾] 实际上,我们要求的答案就是sigma(ci*(ti-i))(i=1~n),这其中sigma(ci*i)是确定的 那么我们就要最小化sigma(ci*ti) 所以在新的每一秒,就把这一秒开始可以起飞的飞机中,cost最大的那一个拿出来,让他起飞就可以了 证明: 设最大的为m,我们取得另一个为n 那么n*ti+m*(ti+1) >= n*(ti+1)+m*ti 所以取m最好 这个过程用堆实现,懒得手打了,就用了priority_queue Code:…
传送门 解题思路 贪心.对于一段区间中,可以将这段区间中相同的元素同时变成\(c\),但要付出的代价是区间中等于\(c\)的数的个数,设\(sum[i]\)表示等于\(c\)数字的前缀和,Max[i]表示数字\(i\)的最大个数.那么只要\(O(n)\)的扫一遍,维护一下每个数字的\(max\),具体做法是看一下\(Max[a[i]]\)大还是\(sum[i]\)大,如果\(sum\)大的话,说明前面都不变,直接把\(Max\)赋值成\(sum[i]+1\),否则直接让\(Max[i]++\),…
题意: m个水果,n个价格.每种水果只有一个价格. 问如果给每种水果分配价格,使得买的m个水果总价格最小.最大. 输出最小值和最大值. 思路: 贪心. 代码: bool cmp(int a,int b){ return a>b; } string name; map<string,int> mp; int price[200],fruit[200]; int cn; int n,m; int main(){ cin>>n>>m; mp.clear(); cn=0;…
题目链接: 传送门 Discounts time limit per test:3 second     memory limit per test:256 megabytes Description One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as…
题目链接: 传送门 Playlist time limit per test:1 second     memory limit per test:256 megabytes Description Manao's friends often send him new songs. He never listens to them right away. Instead, he compiles them into a playlist. When he feels that his mind…
题目链接 题意: n个数,要保证这n个数完全不相同,求需要把原来的数增加多少,求这个值得最小值   Java 程序 import java.io.PrintStream; import java.util.Arrays; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class B546 { static void run(){ Scanner in = new Scanner(S…
Amr and Music time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an ide…
(- ̄▽ ̄)-* //把最大单独放,然后第二大的和最小的放一起,第三大的和第二小的放一起 //由此类推,求最大值,即为盒的最小值 #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<string> #include<cstdlib> #include<vector>…
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cstring> using namespace std; ; char s[MAXN]; int main() { int n; scanf("%d",&n); scanf("%s",s);//输入01串 ,flip=; ;i<strlen(s);i++) { ]) flip++;//00或11 else o…
题意 (Codeforces 546B) 问对一个序列最少需要增减几个1能使其彼此不同. 分析 模拟处理.需要注意的是,尽管题目中说了an<=3000,问题是,如果一群a全是3000呢(滑稽),所以数组要开到6k. 可以说非常阴险了. 代码 #include <bits/stdc++.h> #define MP make_pair #define PB push_back #define fi first #define se second #define ZERO(x) memset(…
题目链接:https://vjudge.net/problem/CodeForces-546B AC代码: #include<iostream> #include<algorithm> using namespace std; int main() { ]; cin>>n; ;i<n;i++) cin>>a[i]; sort(a,a+n); ,t=a[]; ;i<n;i++) { if (a[i]>t) t=a[i]; else { tot…
A. Soldier and Bananas   A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana). He has n dollars. How many d…
A. Soldier and Bananas 题意:有个士兵要买w个香蕉,香蕉起步价为k元/个,每多买一个则贵k元.问初始拥有n元的士兵需要借多少钱? 思路:简单题 #include<iostream> #include<cstdio> using namespace std; int main() { int k, n, w; scanf("%d%d%d", &k, &n, &w); + w)*w / ; if (tot <= n…
A. Soldier and Bananas time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second…
1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优先队列 #include<bits/stdc++.h> #define F(i,a,b) for (int i=a;i<b;i++) #define FF(i,a,b) for (int i=a;i<=b;i++) #define mes(a,b) memset(a,b,sizeof(…
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符的dis之和,求和给定的字符串的dis为d的字符串,若含有多个则输出任意一个,不存在输出-1 解题思路:简单贪心,按顺序往后,对每一个字符,将其变为与它dis最大的字符(a或者z),d再减去相应的dis, 一直减到d为0,剩余的字母则不变直接输出.若一直到最后一位d仍然大于0,则说明不存在,输出-1. /…
题目:http://codeforces.com/contest/949/problem/D 有二分答案的思路. 如果二分了一个答案,首先可知越靠中间的应该大约越容易满足,因为方便把别的房间的人聚集过来:所以如果二分了答案为 f ,可以认为合法的房间是除了前 f 个和后 f 个的剩下的房间. 但边缘房间自己能满足时也不用专门往中间跑,但一旦要跑,方向一定是向中间的:所以可以用指针判断: 可以认为 f 是合法房间的一个界限:指针走的时候累计一下已经有多少人,当又满足一个房间时,如果指针在界限 f…