CF379C-New Year Ratings Change
https://www.luogu.org/problemnew/show/CF379C
一道水题,折腾了我好久!
解题:
先排序,从小到大挨个满足客户,把最终rating放进集合里,判断是否已经给出,如果这个期望rating已经存在,那么取集合里最大的rating+1,既要满足期望,又不能重复,从小到大排序,每次取最大+1;
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
#include<set>
#include<cstring>
#include<queue>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std; int n;
struct node
{
int x;///原来的数据
int id;
};
node a[]; bool cmp1(node p1,node p2)
{
return p1.x<p2.x; }
bool cmp2(node p1,node p2)
{
return p1.id<p2.id;
} int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<n;i++)
scanf("%d",&a[i].x),a[i].id=i;
sort(a,a+n,cmp1);
set<int>se;
se.insert(a[].x);
set<int>::iterator it;
for(int i=;i<n;i++)
{
it=se.end();
it--;
if( se.count(a[i].x) )///该x已经在set里
{
a[i].x=*it+;
}
se.insert(a[i].x);
} sort(a,a+n,cmp2);
for(int i=;i<n;i++)
printf("%d ",a[i].x);
printf("\n");
}
return ;
}
CF379C
CF379C-New Year Ratings Change的更多相关文章
- codeforces C. New Year Ratings Change 解题报告
题目链接:http://codeforces.com/problemset/problem/379/C 题目意思:有n个users,每个user都有自己想升的rating.要解决的问题是给予每个人不同 ...
- cf C. New Year Ratings Change
http://codeforces.com/contest/379/problem/C 思路:先排序,然后判断如果rating>ans,ans=rating否则ans++;然后对应的位置输出就可 ...
- Java和PHP哪个方向更有前途?
Java和PHP到底哪个方向更有前途呢?我从网络上收集了很多资料,并在这篇文章中做了总结. 1.TIOBE语言排行榜 Apr 2014 Apr 2013 Change Programming ...
- TIOBE Index for January 2016(转载)
Java has won the TIOBE Index programming language award of the year. This is because Java has the la ...
- TIOBE Index for December 2015(转载)
There is hardly any doubt about it, Java will become TIOBE's programming language of the year 2015. ...
- TIOBE Index for November 2015(转载)
原文地址:http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html November Headline: Java once a ...
- Good Bye 2013 C
C. New Year Ratings Change time limit per test 1 second memory limit per test 256 megabytes input st ...
- TIOBE.2017.01最新编程语言排行榜
Jan 2017 Jan 2016 Change Programming Language Ratings Change1 1 Java ...
- codeforces379C
New Year Ratings Change CodeForces - 379C One very well-known internet resource site (let's call it ...
随机推荐
- Lambda表达式和方法引用
1 , 为什么用lambda表达式 将重复固定的代码写法简单化 2 ,lambda表达式的实质 对函数式接口的实现(一个接口中只有一个抽象方法的接口被称为函数式接口) package com.mo ...
- 027 ElasticSearch----全文检索技术02---快速入门
1.基本概念 Elasticsearch也是基于Lucene的全文检索库,本质也是存储数据,很多概念与MySQL类似的. 注意:6.0之前的版本有type(类型)概念,type相当于关系数据库的表,E ...
- vue.js与element-ui实现菜单树形结构
由于业务需要,要求实现树形菜单,且菜单数据由后台返回,在网上找了几篇文章,看下来总算有了解决办法.借鉴文章链接在最底部. 场景:根据业务要求,需要实现活动的树形菜单,菜单数据由后台返回,最后的效果图如 ...
- 避免maven package 打包时执行 mybatis-generator-maven-plugin 插件
一.为什么打包时会执行该插件mybatis-generator-maven-plugin默认绑定了package的生命周期 二.如何解决如果在package和install 执行插件,修改pom中的配 ...
- Flink 源码解析 —— 项目结构一览
Flink 源码项目结构一览 https://t.zsxq.com/MNfAYne 博客 1.Flink 从0到1学习 -- Apache Flink 介绍 2.Flink 从0到1学习 -- Mac ...
- ping程序和tracert(traceroute)背后的故事--ICMP协议
为路由器生,为交换机死,为了Ping通奋斗一辈子-----tracert.cn 上面是一个网络工程师的个人定位,很有意思,哈哈!那么我们来看看ping和tracert都是什么吧 PING (Packe ...
- 开源规则引擎 Drools 学习笔记 之 -- 1 cannot be cast to org.drools.compiler.kie.builder.impl.InternalKieModule
直接进入正题 我们在使用开源规则引擎 Drools 的时候, 启动的时候可能会抛出如下异常: Caused by: java.lang.ClassCastException: cn.com.cheng ...
- NModbus4 读取串口设备数值
使用NModbus4 读取串口 public static void aget() { byte[] array = new byte[8]; using (SerialPort port = new ...
- requestAnimationFrame ---- 请求动画帧。
window.requestAnimationFrame() 告诉浏览器——你希望执行一个动画,并且要求浏览器在下次重绘之前调用指定的回调函数更新动画.该方法需要传入一个回调函数作为参数,该回调函数会 ...
- Js字符串用法
js字符串整理导向图 ---欢迎收藏^ - ^