Gym 101341M Last Man Standing 模拟|贪心
来源:互联网 发布:矩阵乘法 matlab 编辑:程序博客网 时间:2024/06/08 16:33
题目链接:点我
题目大意:给你n个人,然后给你一个非递减序列a1 a2 an 分别表示每个人击杀人数,要求满足游戏规则输出YES并且输出每个人击杀的玩家序号,否则输出No.
代码能力太弱,想了半天不知道怎么写。后来参考一下大佬的代码,非常巧妙。
代码参考:@SmoothLatte
AC代码:
/*2017年8月14日11:32:44模拟M AC*/#include <iostream>#include <map>#include <set>#include <string>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <queue>using namespace std;const int maxn=2e5+10;int kill[maxn];int killer[maxn],bekill[maxn];int main(){int n;long long sum=0;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&kill[i]);//记录每个人击杀人数 sum+=kill[i];}if(sum>=n) printf("NO\n");//如果击杀人数大于等于n,不成立 else{int cur=n,id=0;//从 最后一个人开始扫描//如果其击杀人数大于1,那么记录其ID以及被击杀人的ID,同事id 和 cur 更新 for(int i=n;i>=1;i--){ for(int j=0;j<kill[i];j++){killer[id]=i;bekill[id++]=cur--;}}printf("YES\n");//如果全部存活,那么只输出yes即可 for(int i=0;i<id;i++){printf("%d %d\n",killer[i],bekill[i]);}}return 0;}
阅读全文
0 0
- Gym 101341M Last Man Standing 模拟|贪心
- GCJ 2015Q(Standing Ovation-贪心)
- Gym 101341G I love Codeforces 模拟
- Gym 100712E 贪心
- GYM-100952-Mancala【模拟】
- Gym 100187M - Heaviside Function
- Gym 100513M - Variable Shadowing
- Gym 101341H Perfect Ban 暴力模拟|签到
- Gym - 100338E Numbers 贪心
- Gym 100231D Balloons 贪心
- Gym 100803A(贪心)
- Gym-101257H Card【贪心】
- 【Codeforces Gym 100187F 】+ 贪心
- codeforces-gym-100187-F【贪心】
- Gym 100187F (贪心+覆盖)
- Gym 101606E 【贪心+sort】
- final standing
- this.standing
- Redis介绍以及安装(Linux)
- VIJOS-P1625 精卫填海(背包)
- kafka入门:简介、使用场景、设计原理、主要配置及集群搭建(转)
- linux shell中“=”左右不能有空格, 晕不晕
- Cygwin下载速度慢
- Gym 101341M Last Man Standing 模拟|贪心
- bzoj2002 Bounce 弹飞绵羊 LCT
- hihocoder1336-Matrix Sum(二维树状数组)
- K&R 第二章 类型,运算符 与表达式
- Linux系统学习方法——写给小白
- Idea+Mybatis+Maven+单表增删改查
- git 拉去远程分支出错
- POJ
- RxJava