zoukankan      html  css  js  c++  java
  • CF410div2 D. Mike and distribution

     1 /*
     2  CF410div2 D. Mike and distribution
     3  http://codeforces.com/contest/798/problem/D
     4  构造 
     5  题意:给出两个数列a,b,求选出n/2+1个数对,使得其和的二倍大于各自的数列
     6  思路:对数列a进行排序,因为可以选一半加1个,所以最大的那个我们选出来
     7         然后在剩下的数列中,每隔两个选则b中较大的,
     8         这样可以保证选出的在b中满足条件,并且在a中也满足条件
     9         然而。。。。我他喵的居然忘了读入b数列!!!!
    10  */
    11 #include <cstdio>
    12 #include <algorithm>
    13 #include <cstring>
    14 #include <cmath>
    15 #include <vector>
    16 #include <queue>
    17 #include <iostream>
    18 #include <map>
    19 #include <set>
    20 //#define test
    21 using namespace std;
    22 const int Nmax=1e6+7;
    23 long long a[Nmax],b[Nmax];
    24 int m;
    25 long long s1,s2;
    26 long long now1,now2;
    27 int book[Nmax];
    28 struct Node
    29 {
    30     int a;
    31     int id;
    32 }num[Nmax];
    33 bool cmp(Node a,Node b)
    34 {
    35     return a.a>b.a;
    36 }
    37 int ans[Nmax];
    38 int main()
    39 {
    40     #ifdef test
    41     #endif
    42     int n;
    43     scanf("%d",&n);
    44     for(int i=1;i<=n;i++)
    45     {
    46         scanf("%lld",&a[i]);
    47         num[i].id=i;
    48         num[i].a=a[i];
    49     }
    50     for(int i=1;i<=n;i++)//忘了读入b[],真是醉了,感觉最近不适合写代码。。。
    51         scanf("%lld",&b[i]);
    52     sort(num+1,num+1+n,cmp);
    53     int ans_size=0;
    54     int i=1;
    55     ans[++ans_size]=num[i++].id;
    56     for(;i<=n;i+=2)
    57     {
    58         if(i==n)
    59         {
    60             ans[++ans_size]=num[i].id;
    61             break;
    62         }
    63         if(b[num[i].id]>b[num[i+1].id])
    64             ans[++ans_size]=num[i].id;
    65         else
    66             ans[++ans_size]=num[i+1].id;
    67     }
    68     printf("%d
    ",ans_size);
    69     for(int i=1;i<=ans_size;i++)
    70         printf("%d%c",ans[i],i==ans_size?'
    ':' ');
    71     return 0;
    72 }
  • 相关阅读:
    Haskell Interactive Development in Emacs
    Access Java API in Groovy Script
    手工设置Eclipse文本编辑器的配色
    Color Theme of Emacs
    Gnucash的投资记录
    Special Forms and Syntax Sugars in Clojure
    Use w3m as Web Browser
    SSE指令集加速之 I420转BGR24
    【图像处理】 增加程序速度的方法
    TBB 入门笔记
  • 原文地址:https://www.cnblogs.com/BBBob/p/6751656.html
Copyright © 2011-2022 走看看