2021.1.28--vj补题
B - B
题内容:

Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no more than k other knights. Also, each knight has some number of coins. After a kill, a knight can pick up all victim's coins. Now each knight ponders: how many coins he can have if only he kills other knights? You should answer this question for each knight. Input
The first line contains two integers n and k (1≤n≤105,0≤k≤min(n−1,10)) — the number of knights and the number k from the statement. The second line contains n integers p1,p2,…,pn (1≤pi≤109) — powers of the knights. All pi are distinct. The third line contains n integers c1,c2,…,cn (0≤ci≤109) — the number of coins each knight has. Output
Print n integers — the maximum number of coins each knight can have it only he kills other knights. Examples
Input
4 2
4 5 9 7
1 2 11 33
Output
1 3 46 36
Input
5 1
1 2 3 4 5
1 2 3 4 5
Output
1 3 5 7 9
Input
1 0
2
3
Output
3
Note
Consider the first example. The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has.
The second knight can kill the first knight and add his coin to his own two.
The third knight is the strongest, but he can't kill more than k=2 other knights. It is optimal to kill the second and the fourth knights: 2+11+33=46.
The fourth knight should kill the first and the second knights: 33+1+2=36.
In the second example the first knight can't kill anyone, while all the others should kill the one with the index less by one than their own. In the third example there is only one knight, so he can't kill anyone.
题意:有n个骑士,武力值为p[i],每人拥有c[i]个金币,每个骑士最多杀死k个武力值比他低的骑士,问每个人能获得的最多的金币数为多少?
思路:按武力值进行排序,再选出金币多的k个杀死,计算出金币数
但下面的代码超时了


#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,k;
cin>>n>>k;
long long a[n+5],b[n+5],c[n+5]={0};
for(long long i=0;i<n;i++)
{
cin>>a[i];
}
for(long long i=0;i<n;i++)cin>>b[i];
for(long long i=0;i<n;i++)
{
long long p=0;
for(long long j=0;j<n;j++)
{
if(a[i]>a[j])
{
c[p]=b[j];
++p;
}
}
sort(c,c+p);
int ct=0,num=b[i];
for(long long w=p-1;w>=0;w--)
{
if(ct<k)
{
num+=c[w];
++ct;
}
}
if(i==0)cout<<num;
else cout<<" "<<num;
}
}
修改后正确代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int n,k;
struct person
{
int num;//记录下标
int p;//武力值
int c;//原始的金币数
long long ct;//用于记录下总的金币数 注意要用long long
}s[maxn];
bool cmp(person a,person b)//按武力值排序
{
if(a.p!=b.p)return a.p<b.p;
else return a.c<b.c;
}
bool cmp1(person a,person b)
{
return a.num<b.num;
}
int main()
{
cin>>n>>k;
for(int i=0;i<n;i++)
{
cin>>s[i].p;
s[i].num=i;
}
for(int i=0;i<n;i++)
{
cin>>s[i].c;
s[i].ct=s[i].c;
}
sort(s,s+n,cmp);
multiset<int,greater<int> >ss; //multiset会根据特定的排序原则将元素排序,且multisets允许元素重复
//multiset <int,greater<int> > s;创建一个从大到小排序的类型
multiset<int,greater<int> >::iterator it;
for (int i=0;i<n;i++)
{
int sum=0;
for(it=ss.begin();it!=ss.end();it++)
{
if(sum>=k)break;
s[i].ct+=*it;
sum++;
}
ss.insert(s[i].c);//将每个骑士最初金币值插入到容器中
}
sort(s,s+n,cmp1);//按下标排好序便于输出
for(int i=0;i<n;i++)cout<<s[i].ct<<" ";
cout<<endl;
}
C - C

You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect. Input
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between −100 and 100. Output
Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower). Examples
Input
0 0 6 0 6 6 0 6
1 3 3 5 5 3 3 1
Output
YES
Input
0 0 6 0 6 6 0 6
7 3 9 5 11 3 9 1
Output
NO
Input
6 0 6 6 0 6 0 0
7 4 4 7 7 10 10 7
Output
YES
Note
In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples:
题意:给出两个正方形,第一行是一个正面表示的正方形,第二个是一个旋转四十五度角的正方形,问这两个正方形是否相交
思路:暴力每个正方形中的每个点,若有一点在两个正方形里都存在,则相交
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e3+5;
struct sqart
{
ll x;
ll y;
}a[10],b[10];
bool cmp(sqart a,sqart b)
{
if(a.x==b.x)return a.y<b.y;
else return a.x<b.x;
}
ll vis[maxn][maxn];
bool show()
{
for (ll i=a[1].x;i<=a[4].x;i++)
{
for(ll j=a[1].y;j<=a[4].y;j++)
{
vis[i+100][j+100]=1;//因为范围是-100到100 ,以防下标为负,故+100
}
}
for(ll i=b[1].x;i<=b[3].x;i++)//第二个正方形的左半部分枚举
{
for(ll j=0;j<=i-b[1].x;j++)
{
if(vis[i+100][b[1].y+j+100]||vis[i+100][b[1].y-j+100])
{
return true;
}
}
}
for(ll i=b[2].x;i<=b[4].x;i++)//右半部分
{
for(ll j=0;j<=b[3].y-b[1].y-(i-b[2].x);j++){
if(vis[i+100][b[1].y+j+100]||vis[i+100][b[1].y-j+100])
return true;
}
}
return false;
}
int main()
{
cin>>a[1].x >> a[1].y >> a[2].x >> a[2].y >> a[3].x >> a[3].y >> a[4].x >> a[4].y ;
cin>>b[1].x >> b[1].y >> b[2].x >> b[2].y >> b[3].x >> b[3].y >> b[4].x >> b[4].y ;
memset(vis,0,sizeof(vis));
sort(a+1,a+5,cmp);
sort(b+1,b+5,cmp);
if(show())
{
cout<<"YES"<<endl;
}
else
cout<<"NO"<<endl;
}
2021.1.28--vj补题的更多相关文章
- 2021.5.22 vj补题
		
A - Marks CodeForces - 152A 题意:给出一个学生人数n,每个学生的m个学科成绩(成绩从1到9)没有空格排列给出.在每科中都有成绩最好的人或者并列,求出最好成绩的人数 思路:求 ...
 - QFNU-ACM 2021.10.09 Rating补题
		
A - A CodeForces - 478A 注意点: 和为0时要特判一下. 代码: #include<bits/stdc++.h> using namespace std; int m ...
 - 2021-5-15 vj补题
		
C - Win or Freeze CodeForces - 151C 题目内容: You can't possibly imagine how cold our friends are this w ...
 - 2020.12.20vj补题
		
A - Insomnia cure 题意:一共s只龙,每隔k,l,m,n只龙就会受伤,问这s只龙有多少龙是受伤的 思路:看起来题目范围并不是很多,直接进行循环判断 代码: 1 #include< ...
 - hdu5017:补题系列之西安网络赛1011
		
补题系列之西安网络赛1011 题目大意:给定一个椭球: 求它到原点的最短距离. 思路: 对于一个椭球的标准方程 x^2/a^2 + y^2/b^2 +z^2/c^2=1 来说,它到原点的最短距离即为m ...
 - 2017河工大校赛补题CGH    and  赛后小结
		
网页设计课上实在无聊,便开始补题,发现比赛时候僵着的东西突然相通了不少 首先,"追妹"这题,两个队友讨论半天,分好多种情况最后放弃(可是我连题目都没看啊),今天看了之后试试是不是直 ...
 - 2018 HDU多校第四场赛后补题
		
2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...
 - 2018 HDU多校第三场赛后补题
		
2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...
 - [数]补题ver.
		
上次补题好像把两次训练混在一起了,总之先按时间顺序补完这一次|ू・ω・` ) HDU-6301 不会的东西不能逃避.jpg 红小豆非常讨厌构造题,因为非常不会,并且非常逃避学习这类题,因为总也搞不清楚 ...
 - 4.30-5.1cf补题
		
//yy:拒绝转载!!! 悄悄告诉你,做题累了,去打两把斗地主就能恢复了喔~~~ //yy:可是我不会斗地主吖("'▽'") ~~~那就听两遍小苹果嘛~~~ 五一假期除了花时间建模 ...
 
随机推荐
- mysql8.0----mysqldump抛出:Unknown table 'COLUMN_STATISTICS' in information_schema (1109)
			
问题:我尝试使用mysqldump时,得到以下错误: 复制 $> mysqldump --single-transaction --h -u user -p db > db.sql my ...
 - MFC中L, _T(),TEXT,_TEXT区别以及含义
			
字符串前面加L表示该字符串是Unicode字符串. _T是一个宏,如果项目使用了Unicode字符集(定义了UNICODE宏),则自动在字符串前面加上L,否则字符串不变.因此,Visual C++里边 ...
 - volatile的基本原理
			
volatile这个关键字可能很多朋友都听说过,或许也都用过.在Java 5之前,它是一个备受争议的关键字,因为在程序中使用它往往会导致出人意料的结果.在Java 5之后,volatile关键字才得以 ...
 - 利用Struts2拦截器完成文件上传功能
			
Struts2的图片上传以及页面展示图片 在上次的CRUD基础上加上图片上传功能 (https://www.cnblogs.com/liuwenwu9527/p/11108611.html) 文件上传 ...
 - 【Python机器学习实战】决策树与集成学习(六)——集成学习(4)XGBoost原理篇
			
XGBoost是陈天奇等人开发的一个开源项目,前文提到XGBoost是GBDT的一种提升和变异形式,其本质上还是一个GBDT,但力争将GBDT的性能发挥到极致,因此这里的X指代的"Extre ...
 - jvm学习笔记:类加载过程
			
类加载器子系统 类加载器的作用是加载class文件到内存 加载阶段->链接阶段->初始化阶段 ClassLoader只负责class文件的加载,至于是否能够运行由执行引擎判断 加载的类信息 ...
 - JS010. 三元运算符扩展运用(多层判断语句 / 多条表达式)
			
MDN - 三元运算符 语法 Condition ? exprIfTrue : exprIfFalse 用例: function getFee(isMember) { return(isMember ...
 - Java XXE漏洞典型场景分析
			
本文首发于oppo安全应急响应中心: https://mp.weixin.qq.com/s?__biz=MzUyNzc4Mzk3MQ==&mid=2247485488&idx=1&am ...
 - ECMAScript 2021(ES12)新特性简介
			
简介 ES12是ECMA协会在2021年6月发行的一个版本,因为是ECMAScript的第十二个版本,所以也称为ES12. ES12发行到现在已经有一个月了,那么ES12有些什么新特性和不一样的地方呢 ...
 - PHP中的PDO操作学习(二)预处理语句及事务
			
今天这篇文章,我们来简单的学习一下 PDO 中的预处理语句以及事务的使用,它们都是在 PDO 对象下的操作,而且并不复杂,简单的应用都能很容易地实现.只不过大部分情况下,大家都在使用框架,手写的机会非 ...