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的更多相关文章

  1. codeforces C. New Year Ratings Change 解题报告

    题目链接:http://codeforces.com/problemset/problem/379/C 题目意思:有n个users,每个user都有自己想升的rating.要解决的问题是给予每个人不同 ...

  2. cf C. New Year Ratings Change

    http://codeforces.com/contest/379/problem/C 思路:先排序,然后判断如果rating>ans,ans=rating否则ans++;然后对应的位置输出就可 ...

  3. Java和PHP哪个方向更有前途?

      Java和PHP到底哪个方向更有前途呢?我从网络上收集了很多资料,并在这篇文章中做了总结.   1.TIOBE语言排行榜 Apr 2014 Apr 2013 Change Programming ...

  4. TIOBE Index for January 2016(转载)

    Java has won the TIOBE Index programming language award of the year. This is because Java has the la ...

  5. TIOBE Index for December 2015(转载)

    There is hardly any doubt about it, Java will become TIOBE's programming language of the year 2015. ...

  6. TIOBE Index for November 2015(转载)

    原文地址:http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html November Headline: Java once a ...

  7. Good Bye 2013 C

    C. New Year Ratings Change time limit per test 1 second memory limit per test 256 megabytes input st ...

  8. TIOBE.2017.01最新编程语言排行榜

    Jan 2017     Jan 2016     Change     Programming Language     Ratings     Change1    1        Java   ...

  9. codeforces379C

    New Year Ratings Change CodeForces - 379C One very well-known internet resource site (let's call it ...

随机推荐

  1. CentOS7 下 yum 安装 Docker CE

    前言 Docker 使用越来越多,安装也很简单,本次记录一下基本的步骤. Docker 目前支持 CentOS 7 及以后的版本,内核要求至少为 3.10. Docker 官网有安装步骤,本文只是记录 ...

  2. [转帖]油猴脚本管理器 Tampermonkey v4.8 离线CRX安装包(谷歌浏览器版)

    https://www.52pojie.cn/thread-1010604-1-1.html 油猴脚本管理器 Tampermonkey v4.8 离线CRX安装包(谷歌浏览器版) 链接:https:/ ...

  3. 存储过程中的BeginEnd

    存储过程中的BeginEnd和其它语言中的花括号,本身没有事务作用,主要有两个作用1.使语句结果清晰2.语句块作用,比如在 if 后面使用.

  4. Linux 中mysql安装(源码安装方式)

    本文是介绍以源码安装的方式编译和安装Mysql 5.6(可以指定安装路径),也可以不采用源码安装方式,直接用安装包的方式. 源码安装方式慎用,容易报错. 1.卸载旧版本 rpm -qa | grep ...

  5. SQL系列(一)—— SQL简介

    在说到SQL之前需要了解一些关于数据库的概念: 数据库(database):是一个以某种有组织的方式存储的数据集合.存储数据的仓库,不过是以一定的组织方式进行存储. DBMS:数据库管理系统.经常遇到 ...

  6. 【LeetCode】48. Rotate Image

    Difficulty:medium  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/rotate-image/ ...

  7. 谨记不要在MySQL中使用“utf8”编码

    掉坑回顾: 最近在工作中遇到一个BUG,用于记录客户昵称的数据表,在插入带有表情的字符时候报错.使用的存储引擎是INNODB,当我查看数据库字段的时候确实是设置的utf8,我传入的字符也是utf8的编 ...

  8. 【vue】搭建vue环境以及要安装的所有东西

    参考地址: https://www.cnblogs.com/laizhouzhou/p/8027908.html

  9. spring Aop切面中的@Before @Around等执行顺序与请求参数统一解码

    1.背景 在实际开发中,我可能会对请求接口做统一日志输出,或者统一参数解析,验签,统一响应加密等,通常会用到aop,实际案例如下 2.代码 package com.qianxingniwo.log; ...

  10. C# Winform 文本框默认提示信息

    private string Notes = "提示文本"; private void textBox1_Leave(object sender, EventArgs e) { / ...