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 ...
随机推荐
- 12.JAVA-基本数据类型的包装类操作
1.基本数据类型的包装类 java是一个面向对象编程语言,也就是说一切操作都要用对象的形式进行.但是有个矛盾: 基本数据类型(char,int,double等)不具备对象特性(不携带属性和方法) 这样 ...
- arcgis jsapi接口入门系列(2):图层基础操作
//图层相关demo layerFun: function () { //获取地图的所有图层(不包括的图层类型:底图图层(basemaps)) let layers = this.map.layers ...
- xp密钥
Windows XP 专业版 : CCC64-69Q48-Y3KWW-8V9GV-TVKRM
- [windows]解决Win7访问Windows 2003、XP共享慢的问题
解决方法: 1. 修改网卡配置打开本地连接属性,点击"配置"在"高级"选项卡中,将"大型发送分载(IPv4)"的值设置成"禁用&q ...
- SAP成都研究院郑晓霞:Shift Left Testing和软件质量保证的一些思考
今天的文章来自Jerry的同事,曾经的搭档郑晓霞(Zheng Kate).郑晓霞是在Jerry心中是一位很有实力的程序媛,2011年从西安某软件公司跳槽到SAP成都研究院.当时,成都研究院的CRM团队 ...
- UVA - 1658 Admiral (最小费用最大流)
最短路对应费用,路径数量对应流量.为限制点经过次数,拆点为边.跑一次流量为2的最小费用最大流. 最小费用最大流和最大流EK算法是十分相似的,只是把找增广路的部分换成了求费用的最短路. #include ...
- codeforces Gym 100338F Spam Filter 垃圾邮件过滤器(模拟,实现)
阅读题, 概要:给出垃圾邮件和非垃圾邮件的集合,然后按照题目给出的贝叶斯公式计算概率一封邮件是垃圾邮件的概率. 逐个单词判断,将公式化简一下就是在垃圾邮件中出现的次数和在总次数的比值,大于二分之一就算 ...
- abp viewmodel的写法
我的写法 public class QuotaCreateOrEditViewModel { public QuotaDto LoanQuota { get; set; } public bool I ...
- 在行列都排好序的矩阵中找数 【题目】 给定一个有N*M的整型矩阵matrix和一个整数K, matrix的每一行和每一 列都是排好序的。实现一个函数,判断K 是否在matrix中。 例如: 0 1 2 5 2 3 4 7 4 4 4 8 5 7 7 9 如果K为7,返回true;如果K为6,返 回false。 【要求】 时间复杂度为O(N+M),额外空间复杂度为O(1)。
从对角考虑 package my_basic.class_3; /** * 从对角开始 */ public class Code_09_FindNumInSortedMatrix { public s ...
- Java第十二次作业:什么是一维数组?什么是对象数组?吃金币游戏2.0版 新增炸弹功能 新增游戏倒计时功能 新增胜利失败检测功能 使用如鹏游戏引擎制作窗体 一维数组设置金币
什么是数组? 数组的定义:是用统一的名字代表这批数据,用序号来区分各个数据.数组是无序的数据元素按有序的下标组成的集合,分配固定空间大小的一种容器. 如何理解:其实就是一个同时放很多数据的变量. a= ...