Codeforces Round #493 (Div. 2) A. Balloons 贪心水题
由于是输出任意一组解,可以将价值从小到大进行排序,第一个人只选第一个,第二个人选其余的。再比较一下第一个人选的元素和第二个人所选元素和是否相等即可。由于已将所有元素价值从小到大排过序,这样可以保证在有解的情况下一定可以构造出可行解。
Code:
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 100000 + 3;
int a[maxn], A[maxn];
bool cmp(int i,int j) { return a[i] < a[j];}
int main()
{
int n;
cin >> n;
for(int i = 1;i <= n; ++i){ cin >> a[i]; A[i] = i; }
if(n == 1) { cout << -1 ; return 0; }
sort(A + 1, A + 1 + n,cmp);
int sum = 0;
for(int i = 2; i <= n; ++i) sum += a[A[i]];
if(sum == a[A[1]]) cout << -1;
else cout << 1 << "\n" << A[1] ;
return 0;
}
Codeforces Round #493 (Div. 2) A. Balloons 贪心水题的更多相关文章
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #249 (Div. 2)B(贪心法)
B. Pasha Maximizes time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #493 (Div 2) (A~E)
目录 Codeforces 998 A.Balloons B.Cutting C.Convert to Ones D.Roman Digits E.Sky Full of Stars(容斥 计数) C ...
- Cutting Codeforces Round #493 (Div. 2)
Cutting There are a lot of things which could be cut — trees, paper, “the rope”. In this problem you ...
- Codeforces Round #493 (Div. 2)
C - Convert to Ones 给你一个01串 x是反转任意子串的代价 y是将子串全部取相反的代价 问全部变成1的最小代价 两种可能 一种把1全部放到一边 然后把剩下的0变成1 要么把所有的 ...
- Codeforces Round #493 (Div. 1)
A. /* 发现每次反转或者消除都会减少一段0 当0只有一段时只能消除 这样判断一下就行 */ #include<cstdio> #include<algorithm> #in ...
- Codeforces Round #493 (Div. 2)D. Roman Digits 第一道打表找规律题目
D. Roman Digits time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
随机推荐
- MaterialDesign动画
一.概述 MaterialDesign设计理念 MaterialDesign动画 二.实例讲解 (1)Touch Feedback (2)Reveal Effect (3)Activity Trans ...
- Nginx Location指令配置及常用全局变量
./configure的含义 在实践安装nginx的时候,不知道./configure是什么意思,这里特地记录一下. 在linux中./代表当前目录,属于相对路径../代表上一级目录,属于相对路径/代 ...
- 计蒜客 宝藏 (状压DP)
链接 : Here! 思路 : 状压DP. 开始想直接爆搜, T掉了, 然后就采用了状压DP的方法来做. 定义$f[S]$为集合$S$的最小代价, $dis[i]$则记录第$i$个点的"深度 ...
- Project Euler 38 Pandigital multiples
题意: 将192分别与1.2.3相乘: 192 × 1 = 192192 × 2 = 384192 × 3 = 576 连接这些乘积,我们得到一个1至9全数字的数192384576.我们称192384 ...
- Ubuntu14.04 Anaconda
我虚拟机Ubuntu14.04上的Python已经存在了两个版本,一个是python 2.7,一个是Python 3.4.想在它上面安装Anaconda,但又有所顾虑.我先想到的是,先卸载Ubuntu ...
- 使用Word2016直接发布博客
使用Word2016直接发布博客
- HDU 2553 N皇后问题 (DFS_回溯)
Problem Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即随意2个皇后不同意处在同一排,同一列,也不同意处在与棋盘边框成45角的斜线上. 你的任务是.对于给定的N ...
- ym——物联网入口之中的一个Android蓝牙4.0
转载请注明本文出自Cym的博客(http://blog.csdn.net/cym492224103),谢谢支持! 假设还有同学不知道蓝牙4.0能够做什么请查看Android+蓝牙 4.0 将带来什么? ...
- JPEG压缩图像超分辨率重建算法
压缩图像超分辨率重建算法学习 超分辨率重建是由一幅或多幅的低分辨率图像重构高分辨率图像,如由4幅1m分辨率的遥感图像重构分辨率0.25m分辨率图像.在军用/民用上都有非常大应用. 眼下的超分辨率重建方 ...
- Oracle数据处理
DML语言 &:地址符:(PrepareStament) 批处理:插入--------一次将10号部门的员工插入新的表中: ...