Educational Codeforces Round 55 (Rated for Div. 2) A/B/C/D
http://codeforces.com/contest/1082/problem/A
WA数发,因为默认为x<y = =
分情况讨论,直达 or x->1->y or x->n->y 取最小值。
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
//#define debug
int main(){
#ifdef debug
ifstream cin("C:/Users/Administrator/Desktop/test/in.txt");
#endif debug
LL t;
cin>>t;
while(t--){
LL n,x,y,d;
cin>>n>>x>>y>>d;
if(abs(y-x)%d==){
cout<<abs(y-x)/d<<endl;
}
else{
bool ok=;
LL ans=;
if((y-)%d==){
ok=;
ans=min(ans,(y-)/d+(LL)(ceil(1.0*(x-)/d)));
}
if((n-y)%d==){
ok=;
ans=min(ans,(n-y)/d+(LL)(ceil(1.0*(n-x)/d)));
}
if(ok==){
cout<<-<<endl;
}
else{
cout<<ans<<endl;
}
}
}
return ;
}
http://codeforces.com/contest/1082/problem/B
预处理G个数的前后缀长度,然后枚举所有S,考虑交换能达到的最大值。
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
//#define debug
void f(){
char s[];
int l[]={},r[]={};
int n,G=,S=,ans=;
cin>>n>>s+;
for(int i=;i<=n;++i){
if(s[i]=='S') l[i]=,S++;
else l[i]=l[i-]+,G++;
if(l[i]>ans)ans=l[i];
}
r[n+]=;
for(int i=n;i>=;--i){
if (s[i]=='S') r[i]=;
else r[i]=r[i+]+;
}
if(S<){
cout<<n-S<<endl;
return;
}
for(int i=;i<=n;++i){
if(s[i]=='S'){
ans=max(ans,l[i-]+r[i+]+);
}
}
if(ans>G)ans=G;
cout<<ans<<endl; }
int main(){
#ifdef debug
ifstream cin("C:/Users/Administrator/Desktop/test/in.txt");
#endif debug
f();
return ;
}
http://codeforces.com/contest/1082/problem/C
C的题意是给出n个人的专长(m种)si和对应的熟练度ri,挑出一部分人组成一个团体,要求团体中每个不同的专长对应的人数一致。求使得团队熟练度总和最大是多少。
对专长进行分类,然后按照熟练度降序求前缀和。然后枚举不同专长对应的人数即可,需要注意的是有一个优化是对专长人数进行降序排列后再进行查找会节省很多时间,因为当到达某个专长时的人数不足以满足,可以及时的break。
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
//#define debug
LL s[],r[],x[];
std::vector<LL> v[];
bool cmp(int i,int j){
return v[i].size()>v[j].size();
}
int main(){
#ifdef debug
ifstream cin("C:/Users/Administrator/Desktop/test/in.txt");
#endif debug
LL n,m;
cin>>n>>m;
//for(int i=1;i<=m;++i)v[i].push_back(0);
for(int i=;i<=n;++i){
//cin>>s[i]>>r[i];
scanf("%lld%lld",s+i,r+i);
v[s[i]].push_back(r[i]);
}
int maxn=;
for(int i=;i<=m;++i){
sort(v[i].begin(),v[i].end(),greater<LL>());
maxn=max(maxn,(int)(v[i].size()));
}
LL ans=;
for(int i=;i<=m;++i){
x[i]=i;
for(int j=;j<v[i].size();++j){
v[i][j]+=v[i][j-];
}
}
sort(x+,x++m,cmp);
for(int i=;i<=maxn;++i){
LL tmp=;
for(int j=;j<=m&&v[x[j]].size()>=i;++j){
if(v[x[j]][i-]>) tmp+=v[x[j]][i-];
}
if(tmp>ans)ans=tmp;
}
cout<<ans<<endl;
return ;
}
http://codeforces.com/contest/1082/problem/D
D题的题意是给出n个点以及他们的度数,询问是否可以构造出一幅无自环无重边的无向图且使得任意两点最短距离的最大值尽可能的大。
其实是个很简单的构造题,按照度数降序排列之后,先尽可能的组成一条链,然后看看剩下的孤独点是否可以加在树上即可。
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
struct node
{
int id,a;
}x[];
bool cmpa(node A,node B){return A.a>B.a;}
std::vector<int> g[];
void add(int i,int j){
g[i].push_back(j);
g[j].push_back(i);
}
int main(){
int n,i,j,m=;
cin>>n;
for(i=;i<=n;++i){
x[i].id=i;
cin>>x[i].a;
}
sort(x+,x++n,cmpa);
int l=;
for(i=;i<=n;i++){
x[i].a--,x[i-].a--;
add(x[i].id,x[i-].id);
m++;
l++;
if(x[i].a==)break;
}
int md=i++;
int o=;
while(i<=n){
bool ok=;
for(j=;j<=md;++j){
if(x[j].a>=){
o=;
ok=;
x[j].a--;
x[i].a--;
add(x[i].id,x[j].id);
i++;m++;
break;
}
}
if(!ok)break;
}
l+=o;
if(i<=n){puts("NO");}
else{
cout<<"YES "<<l<<endl;
cout<<m<<endl;
for(i=;i<=n;++i){
for(j=;j<g[i].size();++j){
if(g[i][j]>i){
cout<<i<<' '<<g[i][j]<<endl;
}
}
}
}
return ;
}
Educational Codeforces Round 55 (Rated for Div. 2) A/B/C/D的更多相关文章
- Educational Codeforces Round 55 (Rated for Div. 2) C. Multi-Subject Competition 【vector 预处理优化】
传送门:http://codeforces.com/contest/1082/problem/C C. Multi-Subject Competition time limit per test 2 ...
- Educational Codeforces Round 55 (Rated for Div. 2) B. Vova and Trophies 【贪心 】
传送门:http://codeforces.com/contest/1082/problem/B B. Vova and Trophies time limit per test 2 seconds ...
- Codeforces 1082 C. Multi-Subject Competition-有点意思 (Educational Codeforces Round 55 (Rated for Div. 2))
C. Multi-Subject Competition time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces 1082 A. Vasya and Book-题意 (Educational Codeforces Round 55 (Rated for Div. 2))
A. Vasya and Book time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Educational Codeforces Round 55 (Rated for Div. 2):E. Increasing Frequency
E. Increasing Frequency 题目链接:https://codeforces.com/contest/1082/problem/E 题意: 给出n个数以及一个c,现在可以对一个区间上 ...
- Educational Codeforces Round 55 (Rated for Div. 2):D. Maximum Diameter Graph
D. Maximum Diameter Graph 题目链接:https://codeforces.com/contest/1082/problem/D 题意: 给出n个点的最大入度数,要求添加边构成 ...
- Educational Codeforces Round 55 (Rated for Div. 2):C. Multi-Subject Competition
C. Multi-Subject Competition 题目链接:https://codeforces.com/contest/1082/problem/C 题意: 给出n个信息,每个信息包含专业编 ...
- Educational Codeforces Round 55 (Rated for Div. 2)E
题:https://codeforces.com/contest/1082/problem/E 题意:给出n个数和一个数c,只能操作一次将[L,R]之间的数+任意数,问最后该序列中能存在最多多少个c ...
- Educational Codeforces Round 55 (Rated for Div. 2)
D. Maximum Diameter Graph 题意 给出每个点的最大度,构造直径尽可能长的树 思路 让度数大于$1$的点构成链,考虑是否能在链的两端加度为$1$的点 代码 #include &l ...
随机推荐
- Twenty score
1.上图中有两个人对读书的看法有较大的不同. There are two people in the cartoon who treat books in completely different w ...
- 关于导入geoserver 源码到Eclipse编译运行
参考http://blog.csdn.net/gisshixisheng/article/details/43016443 和 http://blog.sina.com.cn/s/blog_6e37 ...
- 把一个List拆分为几个大小一样的List
static void Main(string[] args) { List<String> tarArr = new List<String>(); tarArr.Add(& ...
- 33 Python 详解命令解析 - argparse--更加详细--转载
https://blog.csdn.net/lis_12/article/details/54618868 Python 详解命令行解析 - argparse Python 详解命令行解析 - arg ...
- C++图形开发相关
1. WxWidgets 2. GTK+ 3. U++ Framework 4. QT
- onpause 与 onresume
- Appium-desktop的下载&安装
下载地址: http://appium.io/ 选择版本 双击安装
- JavaSE 字符串和正则表达式
根据不懂的自己整理一下,跟着老师进度刷一遍课本,记录琐碎不懂知识 1.StringTokenizer类 String[] mess= {"整数部分","小数部分" ...
- 为HTML表格添加交互功能------DataTables
DataTables是一个功能强大的Javascript库,用于为HTML表格添加交互功能,虽然简单性是整个项目的核心设计原则,但入门看起来相当艰巨.但是,采取这些第一步并在您的网站上运行DataTa ...
- python获取子进程的返回值
用subprocess popen 的communicate 比如,用gdalinfo命令查看一个tiff文件的信息 x = subprocess.Popen(["gdalinfo&qu ...