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 ;
}
 

最新文章

  1. ASP.NET MVC5中View-Controller间数据的传递
  2. Redis常用五大数据类型
  3. pod setup 安装的最新办法(大坑啊)
  4. ORA-27101 ORACLE not available
  5. 前端利器---Bootstrap
  6. 处理某个json文件的代码
  7. php设计模式 策略模式
  8. 不同gdb,相同数据集合并
  9. LA 3882 And Then There Was One
  10. 使用arm开发板搭建无线mesh网络(一)
  11. leetcode 题解:Remove Duplicates from Sorted Array II(已排序数组去三次及以上重复元素)
  12. Failed to execute goal.....webxml attribute is required...
  13. YII2数据库操作出现类似Database Exception – yii\db\Exception SQLSTATE
  14. struts 2 debug标签隐藏不显示
  15. zookeeper 安装 windows环境
  16. vue.js 常用语法总结(一)
  17. Node.js web快速入门 --&#160;KoaHub.js
  18. Flask图书管管理表
  19. JavaWeb开发的一些问题
  20. Redis日常操作命令小结

热门文章

  1. Oracle数据仓库创建教程
  2. Azure CLI 2.0-Azure新命令行工具介绍
  3. winform重绘
  4. POJ 3133 Manhattan Wiring (插头DP,轮廓线,经典)
  5. ubuntu 16.04 国内源安装docker
  6. Git强制pull
  7. make与makefile的几个例子和(自己写一下,汗!忘记了!)总结
  8. JS对输入判断变化屏蔽中文输入法输入时连续触发事件的方法
  9. CentOS 6.7安装(一)
  10. django 第一次运行出错