Codeforces Round #307 (Div. 2)
2 seconds
256 megabytes
standard input
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 B, A 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.
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).
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.
3
1 3 3
3 1 1
1
1
1
5
3 5 3 4 5
4 1 4 3 1
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美滋滋
2 seconds
256 megabytes
standard input
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 a, b, 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?
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.
Find one of possible strings k, as described in the problem statement. If there are multiple possible answers, print any of them.
aaa
a
b
aaa
pozdravstaklenidodiri
niste
dobri
nisteaadddiiklooprrvz
abbbaaccca
ab
aca
ababacabcc
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)的更多相关文章
- 字符串处理/贪心 Codeforces Round #307 (Div. 2) B. ZgukistringZ
题目传送门 /* 题意:任意排列第一个字符串,使得有最多的不覆盖a/b字符串出现 字符串处理/贪心:暴力找到最大能不覆盖的a字符串,然后在b字符串中动态得出最优解 恶心死我了,我最初想输出最多的a,再 ...
- 水题 Codeforces Round #307 (Div. 2) A. GukiZ and Contest
题目传送门 /* 水题:开个结构体,rk记录排名,相同的值有相同的排名 */ #include <cstdio> #include <cstring> #include < ...
- 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 ...
- 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/ ...
- Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力
B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...
- 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/ ...
- 「日常训练」ZgukistringZ(Codeforces Round #307 Div. 2 B)
题意与分析(CodeForces 551B) 这他妈哪里是日常训练,这是日常弟中弟. 题意是这样的,给出一个字符串A,再给出两个字符串B,C,求A中任意量字符交换后(不限制次数)能够得到的使B,C作为 ...
- Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations (矩阵高速幂)
题目地址:http://codeforces.com/contest/551/problem/D 分析下公式能够知道,相当于每一位上放0或者1使得最后成为0或者1.假设最后是0的话,那么全部相邻位一定 ...
- Codeforces Round #307 (Div. 2) E. GukiZ and GukiZiana (分块)
题目地址:http://codeforces.com/contest/551/problem/E 将n平均分成sqrt(n)块,对每一块从小到大排序,并设置一个总体偏移量. 改动操作:l~r区间内,对 ...
- 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 ...
随机推荐
- Java编程基础-反射
一.java反射 1.反射:动态获取类的信息,以及动态调用对象的方法的功能.可以理解为动态看透类的能力. 2.主要功能:在运行时判断任意一个对象所属的类:在运行时构造任意一个类的对象:在运行时判断任意 ...
- 浅析ES6中的iterator
1.iterator迭代器必须保证其遍历终止条件可控,否则会形成死循环demo: //会用到iterator接口的场合 //1.for...of循环 //2. ...解构表达式 const obj = ...
- css绝对定位元素实现居中的几个方法
一:CSS绝对定位元素left设为50%实现水平居中 绝对定位的元素left设为50%时,是已左上角为原点的,所以只要再使用margin属性添加负值补偿回来即可.示例:[css]代码如下: #boar ...
- css布局两边固定中间自适应的四种方法
第一种:左右侧采用浮动 中间采用margin-left 和 margin-right 方法. 代码如下: <div style="width:100%; margin:0 auto;& ...
- python中中括号中的负数
>>> a="a,b,c,d,e">>> a.split(",")[0:2]['a', 'b']>>> a ...
- SAP产品的Field Extensibility
SAP开发人员的工作职责,除了实现软件的功能性需求外,还会花费相当的精力实现一些非功能性需求,来满足所谓的SAP Product Standard(产品标准).这些产品标准,包含在SAP项目实施中大显 ...
- python在d盘,robotframework引入seleniumlibrary报错
在*** setting*** 中引入库 Library SeleniumLibrary 报错 unknown seleniumlibrary library ,try to use quic ...
- 计算机图形学:贝塞尔曲线(Bezier Curve)
计算机图形学:贝塞尔曲线(Bezier Curve) 贝塞尔能由贝塞尔样条组合而成,也可产生更高维的贝塞尔曲面.
- python之编码的进阶
识记点: ascii 不支持中文 gbk 国标 中文2 英文1 unicode 万国码 英文2 中文4 utf-8 英文1 欧洲2 亚洲3 硬盘中存储的是字节 用什么编码就用什么解码 # 一段文字的转 ...
- 一. python基础知识
第一章.变量与判断语句 1.第一个python程序 # -*- coding:utf-8 -*- # Author: Raymond print ("hello world") p ...