Codeforces Round #508 (Div. 2) C D
C: C - Gambling
给你两个数列 每一回合A可以选择从第一个序列里面选一个数或者清除第二个序列里面选一个数 同理B能从第二序列里面选数或者清除第一个序列里面一个数
然后 求A所选的数之和-B所选数之和最大
贪心就行 两个优先队列每次比较另外一个序列最大的数是比自己序列最大的数大还是小 大就删除另一个序列的数 小就加上自己序列最大的数
可能会爆int QAQ
- #include<bits/stdc++.h>
- using namespace std;
- #define LL long long
- priority_queue <LL ,vector<LL >,less<LL > >q,w;
- int main(){
- LL n;
- cin>>n;
- ;j<n;j++){
- LL x;
- cin>>x;
- q.push(x);
- }
- ;j<n;j++){
- LL x;
- cin>>x;
- w.push(x);
- }
- ;j<n/;j++){
- q.push();
- w.push();
- }
- LL l=;
- LL ans=,ans1=;
- while(!q.empty()&&!w.empty()){
- LL x=q.top(),y=w.top();
- ==){
- if(x<y) w.pop();
- else{
- ans+=x;
- q.pop();
- }
- }else{
- if(x>y) q.pop();
- else{
- ans1+=y;
- w.pop();
- }
- }
- l++;
- }
- cout<<ans-ans1<<endl;
- ;
- }
给你一个序列 每次可以选两个相邻的数 组合成一个新的数 结果为 A-B
让你求当合并到一个数的时候求这个数的最大值
当全是正数(>=0) 或者全是负数的时候直接求出来最大最小 然后序列求和 减去最大或者最小*2 就可以了
当正负数组合时 就直接对序列求和
当时没考虑完全 代码有点乱
- #include<bits/stdc++.h>
- using namespace std;
- #define LL long long
- #define inf 0x3f3f3f3f
- #define maxn 500000+50
- LL a[maxn];
- int main(){
- ;
- cin>>n;
- ;
- ;j<n;j++){
- scanf("%lld",&a[j]);
- ) fa=;
- }
- ) cout<<a[]<<endl;
- ){
- cout<<max(a[]-a[],a[]-a[])<<endl;
- }else{
- LL ans=;
- ){
- LL mi=inf;
- ;j<n;j++){
- mi=min(mi,a[j]);
- ans+=abs(a[j]);
- }
- ans-=mi*;
- cout<<ans<<endl;
- ;
- }else{
- LL i=;
- ;j<n;j++){
- ) i++;
- }
- if(i!=n){
- ;j<n;j++){
- ans+=abs(a[j]);
- }
- cout<<ans<<endl;
- ;
- }else{
- LL mi=-inf;
- ;j<n;j++){
- mi=max(mi,a[j]);
- ans+=abs(a[j]);
- }
- ans+=mi*;
- cout<<ans<<endl;
- ;
- }
- }
- }
- ;
- }
Codeforces Round #508 (Div. 2) C D的更多相关文章
- Codeforces Round #508 (Div. 2)
Codeforces Round #508 (Div. 2) http://codeforces.com/contest/1038 A #include<bits/stdc++.h> us ...
- Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)
E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范 ...
- Codeforces Round #508 (Div. 2) D. Slime
D. Slime 题目链接:https://codeforces.com/contest/1038/problem/D 题意: 给出两个数,然后每次可以对相邻的两个数合并,比如x,y,那么合并过后就是 ...
- [Codeforces Round #508 (Div. 2)][Codeforces 1038E. Maximum Matching]
前几天给舍友讲这题的时候感觉挺有意思的,就贴上来吧... 题目链接:1038E - Maximum Matching 题目大意:有\(n\)个棒子,每个条两端有颜色\(c1,c2\)以及他的价值\(v ...
- 题解——Codeforces Round #508 (Div. 2) T3 (贪心)
贪心的选取最优解 然后相减好 记得要开long long #include <cstdio> #include <algorithm> #include <cstring ...
- 题解——Codeforces Round #508 (Div. 2) T2 (构造)
按照题意构造集合即可 注意无解情况的判断 #include <cstdio> #include <algorithm> #include <cstring> #in ...
- 题解——Codeforces Round #508 (Div. 2) T1 (模拟)
依照题意暴力模拟即可A掉 #include <cstdio> #include <algorithm> #include <cstring> #include &l ...
- Codeforces 1038F Wrap Around (Codeforces Round #508 (Div. 2) F) 题解
写在前面 此题数据量居然才出到\(n=40\)???(黑人问号)以下给出一个串长\(|S|=100,n=10^9\)的题解. 题目描述 给一个长度不超过\(m\)的01串S,问有多少个长度不超过\(n ...
- Codeforces Round #508 (Div. 2)【A,B,C,D】【实验室日常周赛训练】
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f3f3f #define int long long ...
随机推荐
- Vue+iview实现添加删除类
<style> .tab-warp{ border-bottom: solid 1px #e0e0e0; overflow: hidden; margin-top: 30px; posit ...
- 头文件带和不带.h的区别
所有C++标准库的头文件都是没有.h结尾的.这么做是为了区分,C标准库的头文件和C++标准库的头文件.比如最具代表性的: #include <string.h> // C 标准库头文件,包 ...
- vue二次实战(一)
创建好项目(npm run dev 运行项目:先不用运行,或先运行再关闭) 先安装axios! npm install axios 然后! npm install --save axios vue-a ...
- js 解决中文乱码的问题
1.对象 request response 对象setCharacterEncoding=UTF-8 1 <%@ page language="java" contentTy ...
- Appscanner实验还原code2
import _pickle as pickle from sklearn import svm, ensemble import random from sklearn.metrics import ...
- Vue之双向数据绑定
demo.html <!DOCTYPE html> <html lang="en" xmlns:v-bind="http://www.w3.org/19 ...
- powerdesigner 16.5 不允许有扩展属性,或对象不存在
创建完之后这边会出现 选择刚创建的用户 这样就可以了
- spring @Validated 注解开发中使用group分组校验
之前知道spring支持JSR校验,在自己定义的bean中加入@NotNull,@NotBlank,@Length等之类的校验用于处理前台传递过来的request请求,避免在写多余的代码去处理. 但是 ...
- faster rcnn训练详解
http://blog.csdn.net/zy1034092330/article/details/62044941 py-faster-rcnn训练自己的数据:流程很详细并附代码 https://h ...
- 了解AutoCAD对象层次结构 —— 6 ——块表记录
块表记录是包裹实体对象的最后一层包装了,接下来让我们继续利用MgdDbg工具查看上一小节创建的块定义内的对象有哪些. 操作步骤如下:选择块表记录TestBlock,在右侧列表中找到“Entities ...