原文链接https://codeforces.com/contest/1183/problem/B 题意:进行Q组测试,在每组中有长度为n的数组a[i],然后现在给你一个K,问你找到一个bi使得|ai-bi|<=k并且bi最大.如果找不到,就输出-1.思路:这个也就关系到,最大值max,最小值min,和K,至于中间的数,我们不用去管,现在一个排序,如果max-min<=2*k,那么就输出min+k,否者就输出-1.(为什么要在2*k的范围找???想想看)代码: #include"io…
B题题意: 给你n个物品的价格,你需要找出来一个值b,使得每一个物品与这个b的差值的绝对值小于k.找到最大的b输出,如果找不到,那就输出-1 题解: 很简单嘛,找到上下限直接二分.下限就是所有物品中最小的价格.上限就是所有物品中最大价格加上k 代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 #include<map>…
链接: https://codeforces.com/contest/1234/problem/A 题意: You are both a shop keeper and a shop assistant at a small nearby shop. You have n goods, the i-th good costs ai coins. You got tired of remembering the price of each product when customers ask fo…
D. Equalize Them All time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array aa consisting of nn integers. You can perform the following operations arbitrary number of times…
A:暴力从小到大枚举判断. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;} int g…
题意:有一长度为\(n\)的字符串,要求得到\(k\)不同的它的子序列(可以是空串),每个子序列有\(|n|-|t|\)的贡献,求合法情况下的最小贡献. 题解:直接撸个爆搜找出所有子序列然后放到set里面搞一下就好了. 代码: int n,k; string str; set<string> s; queue<string> q; void bfs(){ s.insert(str); q.push(str); while(!q.empty()){ string cur=q.fron…
题意:你有\(n\)个礼物,礼物有自己的种类,你想将它们按种类打包送人,但是打包的礼物数量必须不同(数量,与种类无关),同时,有些礼物你想自己留着,\(0\)表示你不想送人,问你在送出的礼物数量最大的同时,尽可能的使自己喜欢的留下来,输出能送出的最大礼物数,以及这些礼物中自己不喜欢的数目. 题解:首先,我们肯定要让送出的礼物数最大,同时喜欢的最小,也就是送的礼物中,尽量让它的\(f\)是\(1\).这题考虑贪心,我们可以先对礼物数量进行排序,礼物数量相同让\(1\)多的排在前面,全部丢进优先队列…
题意:有一组数,可以选择某个数\(a_i\)相邻的一个数\(a_j\),然后可以让\(a_i\)加上或者减去\(|a_i-a_j|\),问最少操作多少次使得数组中所有数相同. 题解:不难发现,每次操作必然可以使得一个数等于它旁边的任意一个数,所以让数组中的其他数等于出现次数最多的那个数一定是最优的,然后我们就去找与那个数相邻的数去求块,正着反着模拟输出一下就可以了,具体看代码吧. 代码: int n; int a[N]; map<int,int> mp; int mx,res; bool st…
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bough…
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate it n = int(raw_input()) s = "" a = ["I hate that ","I love that ", "I hate it","I love it"] for i in ran…