C: C - Gambling

给你两个数列  每一回合A可以选择从第一个序列里面选一个数或者清除第二个序列里面选一个数 同理B能从第二序列里面选数或者清除第一个序列里面一个数

然后 求A所选的数之和-B所选数之和最大

贪心就行 两个优先队列每次比较另外一个序列最大的数是比自己序列最大的数大还是小 大就删除另一个序列的数 小就加上自己序列最大的数

可能会爆int  QAQ

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define LL long long
  4. priority_queue <LL ,vector<LL >,less<LL > >q,w;
  5. int main(){
  6. LL n;
  7. cin>>n;
  8. ;j<n;j++){
  9. LL x;
  10. cin>>x;
  11. q.push(x);
  12. }
  13. ;j<n;j++){
  14. LL x;
  15. cin>>x;
  16. w.push(x);
  17. }
  18. ;j<n/;j++){
  19. q.push();
  20. w.push();
  21. }
  22. LL l=;
  23. LL ans=,ans1=;
  24. while(!q.empty()&&!w.empty()){
  25. LL x=q.top(),y=w.top();
  26. ==){
  27. if(x<y) w.pop();
  28. else{
  29. ans+=x;
  30. q.pop();
  31. }
  32. }else{
  33. if(x>y) q.pop();
  34. else{
  35. ans1+=y;
  36. w.pop();
  37. }
  38. }
  39. l++;
  40. }
  41. cout<<ans-ans1<<endl;
  42.  
  43. ;
  44. }

D - Slime

给你一个序列 每次可以选两个相邻的数 组合成一个新的数 结果为 A-B

让你求当合并到一个数的时候求这个数的最大值

当全是正数(>=0) 或者全是负数的时候直接求出来最大最小 然后序列求和 减去最大或者最小*2 就可以了

当正负数组合时 就直接对序列求和

当时没考虑完全 代码有点乱

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define LL long long
  4. #define inf 0x3f3f3f3f
  5. #define maxn 500000+50
  6. LL a[maxn];
  7. int main(){
  8. ;
  9. cin>>n;
  10. ;
  11. ;j<n;j++){
  12. scanf("%lld",&a[j]);
  13. ) fa=;
  14. }
  15. ) cout<<a[]<<endl;
  16. ){
  17. cout<<max(a[]-a[],a[]-a[])<<endl;
  18. }else{
  19. LL ans=;
  20. ){
  21. LL mi=inf;
  22. ;j<n;j++){
  23. mi=min(mi,a[j]);
  24. ans+=abs(a[j]);
  25. }
  26. ans-=mi*;
  27. cout<<ans<<endl;
  28. ;
  29. }else{
  30. LL i=;
  31. ;j<n;j++){
  32. ) i++;
  33. }
  34. if(i!=n){
  35. ;j<n;j++){
  36. ans+=abs(a[j]);
  37. }
  38. cout<<ans<<endl;
  39. ;
  40. }else{
  41. LL mi=-inf;
  42. ;j<n;j++){
  43. mi=max(mi,a[j]);
  44. ans+=abs(a[j]);
  45. }
  46. ans+=mi*;
  47. cout<<ans<<endl;
  48. ;
  49. }
  50. }
  51. }
  52. ;
  53. }

Codeforces Round #508 (Div. 2) C D的更多相关文章

  1. Codeforces Round #508 (Div. 2)

    Codeforces Round #508 (Div. 2) http://codeforces.com/contest/1038 A #include<bits/stdc++.h> us ...

  2. Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)

     E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范 ...

  3. Codeforces Round #508 (Div. 2) D. Slime

    D. Slime 题目链接:https://codeforces.com/contest/1038/problem/D 题意: 给出两个数,然后每次可以对相邻的两个数合并,比如x,y,那么合并过后就是 ...

  4. [Codeforces Round #508 (Div. 2)][Codeforces 1038E. Maximum Matching]

    前几天给舍友讲这题的时候感觉挺有意思的,就贴上来吧... 题目链接:1038E - Maximum Matching 题目大意:有\(n\)个棒子,每个条两端有颜色\(c1,c2\)以及他的价值\(v ...

  5. 题解——Codeforces Round #508 (Div. 2) T3 (贪心)

    贪心的选取最优解 然后相减好 记得要开long long #include <cstdio> #include <algorithm> #include <cstring ...

  6. 题解——Codeforces Round #508 (Div. 2) T2 (构造)

    按照题意构造集合即可 注意无解情况的判断 #include <cstdio> #include <algorithm> #include <cstring> #in ...

  7. 题解——Codeforces Round #508 (Div. 2) T1 (模拟)

    依照题意暴力模拟即可A掉 #include <cstdio> #include <algorithm> #include <cstring> #include &l ...

  8. Codeforces 1038F Wrap Around (Codeforces Round #508 (Div. 2) F) 题解

    写在前面 此题数据量居然才出到\(n=40\)???(黑人问号)以下给出一个串长\(|S|=100,n=10^9\)的题解. 题目描述 给一个长度不超过\(m\)的01串S,问有多少个长度不超过\(n ...

  9. Codeforces Round #508 (Div. 2)【A,B,C,D】【实验室日常周赛训练】

    #include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f3f3f #define int long long ...

随机推荐

  1. Vue+iview实现添加删除类

    <style> .tab-warp{ border-bottom: solid 1px #e0e0e0; overflow: hidden; margin-top: 30px; posit ...

  2. 头文件带和不带.h的区别

    所有C++标准库的头文件都是没有.h结尾的.这么做是为了区分,C标准库的头文件和C++标准库的头文件.比如最具代表性的: #include <string.h> // C 标准库头文件,包 ...

  3. vue二次实战(一)

    创建好项目(npm run dev 运行项目:先不用运行,或先运行再关闭) 先安装axios! npm install axios 然后! npm install --save axios vue-a ...

  4. js 解决中文乱码的问题

    1.对象 request response 对象setCharacterEncoding=UTF-8 1 <%@ page language="java" contentTy ...

  5. Appscanner实验还原code2

    import _pickle as pickle from sklearn import svm, ensemble import random from sklearn.metrics import ...

  6. Vue之双向数据绑定

    demo.html <!DOCTYPE html> <html lang="en" xmlns:v-bind="http://www.w3.org/19 ...

  7. powerdesigner 16.5 不允许有扩展属性,或对象不存在

    创建完之后这边会出现 选择刚创建的用户 这样就可以了

  8. spring @Validated 注解开发中使用group分组校验

    之前知道spring支持JSR校验,在自己定义的bean中加入@NotNull,@NotBlank,@Length等之类的校验用于处理前台传递过来的request请求,避免在写多余的代码去处理. 但是 ...

  9. faster rcnn训练详解

    http://blog.csdn.net/zy1034092330/article/details/62044941 py-faster-rcnn训练自己的数据:流程很详细并附代码 https://h ...

  10. 了解AutoCAD对象层次结构 —— 6 ——块表记录

    块表记录是包裹实体对象的最后一层包装了,接下来让我们继续利用MgdDbg工具查看上一小节创建的块定义内的对象有哪些. 操作步骤如下:选择块表记录TestBlock,在右侧列表中找到“Entities ...