A. GukiZ and Contest
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.

In total, n students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to n. Let's denote the rating of i-th student as ai. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings.

He thinks that each student will take place equal to . In particular, if student A has rating strictly lower then student BA will get the strictly better position than B, and if two students have equal ratings, they will share the same position.

GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected.

Input

The first line contains integer n (1 ≤ n ≤ 2000), number of GukiZ's students.

The second line contains n numbers a1, a2, ... an (1 ≤ ai ≤ 2000) where ai is the rating of i-th student (1 ≤ i ≤ n).

Output

In a single line, print the position after the end of the contest for each of n students in the same order as they appear in the input.

Examples
input
3
1 3 3
output
3 1 1
input
1
1
output
1
input
5
3 5 3 4 5
output
4 1 4 3 1
Note

In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.

In the second sample, first student is the only one on the contest.

In the third sample, students 2 and 5 share the first position with highest rating, student 4 is next with third position, and students 1 and 3are the last sharing fourth position.

问你一个数排第几

#include<bits/stdc++.h>
using namespace std;
int a[];
int main(){
int n;
cin>>n;
for(int i=;i<n;i++)
cin>>a[i];
int s=;
for(int j=;j<n;j++)
if(a[j]>a[])s++;
printf("%d",s);
for(int i=;i<n;i++){
s=;
for(int j=;j<n;j++)
if(a[j]>a[i])s++;
printf(" %d",s);}
return ;
}

直接这样枚举也能过,所以,sort的也能过吧

#include<bits/stdc++.h>
using namespace std;
int a[],b[];
int main(){
int n;
cin>>n;
for(int i=;i<n;i++)
cin>>a[i];
copy(a,a+n,b);
sort(b,b+n);
cout<<n-(upper_bound(b,b+n,a[])-b)+;
for(int i=;i<n;i++)
cout<<" "<<n-(upper_bound(b,b+n,a[i])-b)+;
return ;
}

完美,直接upper_bound美滋滋

B. ZgukistringZ
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.

GukiZ has strings ab, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possible. Substring of string x is a string formed by consecutive segment of characters from x. Two substrings of string x overlap if there is position i in string x occupied by both of them.

GukiZ was disappointed because none of his students managed to solve the problem. Can you help them and find one of possible strings k?

Input

The first line contains string a, the second line contains string b, and the third line contains string c (1 ≤ |a|, |b|, |c| ≤ 105, where |s| denotes the length of string s).

All three strings consist only of lowercase English letters.

It is possible that b and c coincide.

Output

Find one of possible strings k, as described in the problem statement. If there are multiple possible answers, print any of them.

Examples
input
aaa
a
b
output
aaa
input
pozdravstaklenidodiri
niste
dobri
output
nisteaadddiiklooprrvz
input
abbbaaccca
ab
aca
output
ababacabcc
Note

In the third sample, this optimal solutions has three non-overlaping substrings equal to either b or c on positions 1 – 2 (ab), 3 – 4 (ab), 5 – 7 (aca). In this sample, there exist many other optimal solutions, one of them would be acaababbcc.

给定A,B,C串,其中A串(可能)包含B或C串,现在可以任意变换A串的位置,使A串中包含B串,C串的总个数最大。

所以贪心下啊,统计字母个数

#include <bits/stdc++.h>
using namespace std;
char a[],b[],c[];
int A[],B[],C[],S[];
int main() {
cin>>a>>b>>c;
int len=strlen(a);
for(int i=; i<len; i++)
A[a[i]-'a']++;
len=strlen(b);
for(int i=; i<len; i++)
B[b[i]-'a']++;
len=strlen(c);
for(int i=; i<len; i++)
C[c[i]-'a']++;
int ans,x,y;
ans=x=y=;
len=strlen(a)/strlen(b);
for(int i=; i<=len; i++) {
int ok=;
memcpy(S,A,sizeof(A));
for(int j=; j<; j++) {
if(B[j]*i>S[j]) {
ok=;
break;
}
S[j]-=B[j]*i;
}
if(!ok)
continue;
int t=;
for(int j=; j<; j++) {
if(C[j]==)
continue;
t=min(t,S[j]/C[j]);
}
if(t+i>ans) {
ans=t+i;
x=i;
y=t;
}
}
for(int i=; i<x; i++)
cout<<b;
for(int i=; i<y; i++)
cout<<c;
for(int i=; i<; i++) {
for(int j=; j<A[i]-x*B[i]-y*C[i]; j++)
cout<<char('a'+i);
}
cout<<endl;
return ;
}
 

Codeforces Round #307 (Div. 2)的更多相关文章

  1. 字符串处理/贪心 Codeforces Round #307 (Div. 2) B. ZgukistringZ

    题目传送门 /* 题意:任意排列第一个字符串,使得有最多的不覆盖a/b字符串出现 字符串处理/贪心:暴力找到最大能不覆盖的a字符串,然后在b字符串中动态得出最优解 恶心死我了,我最初想输出最多的a,再 ...

  2. 水题 Codeforces Round #307 (Div. 2) A. GukiZ and Contest

    题目传送门 /* 水题:开个结构体,rk记录排名,相同的值有相同的排名 */ #include <cstdio> #include <cstring> #include < ...

  3. Codeforces Round #307 (Div. 2) E. GukiZ and GukiZiana 分块

    E. GukiZ and GukiZiana Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55 ...

  4. Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 贪心/二分

    C. GukiZ hates Boxes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...

  5. Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力

    B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...

  6. Codeforces Round #307 (Div. 2) A. GukiZ and Contest 水题

    A. GukiZ and Contest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...

  7. 「日常训练」ZgukistringZ(Codeforces Round #307 Div. 2 B)

    题意与分析(CodeForces 551B) 这他妈哪里是日常训练,这是日常弟中弟. 题意是这样的,给出一个字符串A,再给出两个字符串B,C,求A中任意量字符交换后(不限制次数)能够得到的使B,C作为 ...

  8. Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations (矩阵高速幂)

    题目地址:http://codeforces.com/contest/551/problem/D 分析下公式能够知道,相当于每一位上放0或者1使得最后成为0或者1.假设最后是0的话,那么全部相邻位一定 ...

  9. Codeforces Round #307 (Div. 2) E. GukiZ and GukiZiana (分块)

    题目地址:http://codeforces.com/contest/551/problem/E 将n平均分成sqrt(n)块,对每一块从小到大排序,并设置一个总体偏移量. 改动操作:l~r区间内,对 ...

  10. Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations 矩阵快速幂优化dp

    D. GukiZ and Binary Operations time limit per test 1 second memory limit per test 256 megabytes inpu ...

随机推荐

  1. Json字符串转excel表格文件

    假如我们有一段json串,该json串是由一系列结构相同的数据集合组成,如下: { "data": [ { "groupId": "com.test. ...

  2. Hadoop2.6.2的Eclipse插件的使用

    欢迎转载,且请注明出处,在文章页面明显位置给出原文连接. 本文链接:http://www.cnblogs.com/zdfjf/p/5178197.html 首先给出eclipse插件的下载地址:htt ...

  3. Nginx性能优化参考

    nginx性能优化参考 1)调整配置文件中的配置项的值(配置文件:nginx.conf) worker_processes auto;开启的进程数,一般配置为跟逻辑CPU核数一样worker_rlim ...

  4. C#语言基础 Main 函数中变量 整型

    在我们每次上网或者用电脑的时候,请输入你的xxx 或者你的名字(年龄/身高/学校/籍贯)是 在这里我们就要学到一些变量,就是不确定的东西 string a:   //赋予变量 a ="内容& ...

  5. 如何用JavaScript判断前端应用运行环境(移动平台还是桌面环境)

    我们部署在某些云平台或者Web服务器上的前端应用,既可以用PC端浏览器访问,也可以用手机上的浏览器访问. 在前端应用里,有时候我们需要根据运行环境的不同做出对应处理.比如下面这段逻辑,如果判断出应用当 ...

  6. bzoj 2658

    首先考虑容斥 我们计算出所有没有点在其中的矩形,然后用所有矩形减去这些矩形即可 然后考虑如何计算没有点在其中的矩形 采用扫描线的思想,从上向下一行一行扫,假设我们扫到的行编号是$a$,然后考虑如果左右 ...

  7. 理解Vue

    Vue.js是JavaScript MVVM(Model-View-ViewModel)库,十分简洁,Vue核心只关注视图层,相对AngularJS提供更加简洁.易于理解的API.Vue尽可能通过简单 ...

  8. 转 在Qt中用QAxObject来操作Excel

    最近写程序中需要将数据输出保存到Excel文件中.翻看<C++ GUI Programming with Qt 4>(Second Edition)发现可以在Qt中运用ActiveX控件, ...

  9. 用 Deployment 运行应用【转】

    从本章开始,我们将通过实践深入学习 Kubernetes 的各种特性.作为容器编排引擎,最重要也是最基本的功能当然是运行容器化应用,这就是本章的内容. Deployment 前面我们已经了解到,Kub ...

  10. Delphi 中内存映射对于大文件的使用

    这篇文章主要介绍了Delphi 中内存映射对于大文件的使用的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下 Delphi 中内存映射对于大文件的使用 平时很少使用大文件的内存映射,碰巧遇到了 ...