zoukankan      html  css  js  c++  java
  • Codeforces 798D Mike and distribution (构造)

    题目链接

    http://codeforces.com/contest/798/problem/D

    题解

    前几天的模拟赛,居然出这种智商题。。被打爆了QAQ

    这个的话,考虑只有一个序列怎么做,把所有的排序取最大的当然可以,但是还有一种做法,就是两两分组之后每两个相邻的取大的!!
    于是按照(a)排序,先取第一个,后面每两个相邻的取b较大的。做完了!

    哇这怎么想出来的啊。。。。

    代码

    #include<cstdio>
    #include<cstdlib>
    #include<iostream>
    #include<vector>
    #include<algorithm>
    using namespace std;
     
    const int N = 1e5;
    int a[N+3],b[N+3],permu[N+3];
    vector<int> ans;
    int n;
     
    bool cmp(int x,int y) {return a[x]>a[y];}
     
    int main()
    {
    	scanf("%d",&n);
    	for(int i=1; i<=n; i++) scanf("%d",&a[i]);
    	for(int i=1; i<=n; i++) scanf("%d",&b[i]);
    	for(int i=1; i<=n; i++) permu[i] = i;
    	sort(permu+1,permu+n+1,cmp);
    	ans.push_back(permu[1]);
    	for(int i=2; i<=n; i+=2)
    	{
    		ans.push_back(b[permu[i]]>b[permu[i+1]] ? permu[i] : permu[i+1]);
    	}
    	printf("%d
    ",ans.size());
    	for(int i=0; i<ans.size(); i++) printf("%d ",ans[i]); puts("");
    	return 0;
    }
    
  • 相关阅读:
    Hdu 4496 D-City
    Hdu 1213 How Many Tables
    T1387:搭配购买(buy)
    codevs 2597 团伙
    Hdu 1232 畅通工程
    RQNOJ PID331 家族
    提高组day4
    xjoi2018提高组训训练25
    关于upp和lower
    矩阵快速幂求fib
  • 原文地址:https://www.cnblogs.com/suncongbo/p/11330571.html
Copyright © 2011-2022 走看看