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 ...
随机推荐
- top 进程管理
top 动态查看进程 前五行解释: 第一行参数说明: top - 07:06:19 当前时间 up 10 min, 系统运行时间,格式为时:分 1 user, 当前登录用户数 load av ...
- PLSQL连接Oracle64监听和服务的配置!
前言: 这里不会涉及到太多关于版本问题的解决,只是简单提一下基本的监听和服务配置问题的解决,让你可以快速的用PLSQL连接上你自己创建的Oracle数据库(这里示例数据库名为ORCL); 版本问题: ...
- jQuery源码分析系列(转载来源Aaron.)
声明:非本文原创文章,转载来源原文链接Aaron. 版本截止到2013.8.24 jQuery官方发布最新的的2.0.3为准 附上每一章的源码注释分析 :https://github.com/JsAa ...
- Android 图片在SD卡及包下的存储
public class FileBitmap { /** * 获取sd卡中的bitmap,bitmap可见 * * @param bitmap * 读取bitmap的路径 * @return bit ...
- php关于精准计算的模块 BCMath
Php: BCMath bc是Binary Calculator的缩写.bc*函数的参数都是操作数加上一个可选的 [int scale],比如string bcadd(string $left_ope ...
- License开源许可协议
开源许可协议 License是软件的授权许可,表述了你获得代码后拥有的权利,可以对别人的作品进行何种操作,何种操作又是被禁止的. 开源许可证种类 Open Source Initiative http ...
- 人人必知的10个 jQuery 小技巧
原文地址:http://info.9iphp.com/10-jquery-tips-everyone-should-know/ 人人必知的10个 jQuery 小技巧 收集的10个 jQuery ...
- C++数据文件存储与加载(利用opencv)
首先请先确认已经安装好了opencv3及以上版本. #include <opencv2/opencv.hpp>#include <iostream>#include <s ...
- ant design table td 文字显示过长添加省略号、ant 文字过长时添加tootip提示
方法1: overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit ...
- 多线程threadvar 变量设定
Delphi管理多线程之线程局部存储:threadvar 尽管多线程能够解决许多问题,但是同时它又给我们带来了很多的问题.其中主要的问题就是:对全局变量或句柄这样的全局资源如何访问?另外,当必须确保一 ...