Educational Codeforces Round 2
600A - Extract Numbers 20171106
字符串处理题,稍微注意点细节就能水过
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
string s;int _;
vector<string>a,b;
void check(int l,int r)
{
if(l==r){b.push_back("");return;}
if(l==r-)
{
if(s[l]>='' && s[l]<='')
a.push_back(""),a[a.size()-].assign(s,l,r-l);
else b.push_back(""),b[b.size()-].assign(s,l,r-l);
return;
}
if(s[l]==''){b.push_back(""),b[b.size()-].assign(s,l,r-l);return;}
for(int i=l;i<r;i++)
if(s[i]<'' || s[i]>'')
{
b.push_back("");
b[b.size()-].assign(s,l,r-l);
return;
}
a.push_back("");
a[a.size()-].assign(s,l,r-l);
}
int main()
{
cin>>s;
for(int i=;i<s.size();i++)
if(s[i]==',' || s[i]==';')
check(_,i),_=i+;check(_,s.size());
if(a.size()==)printf("-\n");else{cout<<char();
for(int i=;i<a.size();i++)
{cout<<a[i];printf("%c",i==a.size()-?'"':',');}cout<<endl;}
if(b.size()==)printf("-\n");else{cout<<char();
for(int i=;i<b.size();i++)
{cout<<b[i];printf("%c",i==b.size()-?'"':',');}cout<<endl;}
return ;
}
600B - Queries about less or equal elements 20171106
对a数组排序后upperbound一下就好了,当然想手写二分也不拦着╮(╯▽╰)╭
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,x;
int a[];
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a+n+);
for(int i=;i<=m;i++)
{scanf("%d",&x);cout<<upper_bound(a+,a+n+,x)-a-<<endl;}
return ;
}
600C - Make Palindrome 20171106
由于可以改变排列顺序,所以尽可能地把大的出现次数为奇数的字母改为小的出现次数为奇数的字母一定是最优的
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int pos[],sum[],l,r;
string s;
int main()
{
cin>>s;
for(int i=;i<s.size();i++)
pos[s[i]-'a']=i,sum[s[i]-'a']++;
int mid=-;l=,r=;
while(l<r)
{
while(sum[l]%== && l<)l++;
while(sum[r]%== && r>=)r--;
if(l>=r)break;
s[pos[r]]=l+'a';
sum[l++]++,sum[r--]--;
}
for(int i=;i<;i++)
if(sum[i]&)mid=i;
sort(s.begin(),s.end());
for(int i=;i<s.size();i+=)
{
if(s[i]==mid+'a' && i%==)i++;
if(i<s.size())cout<<s[i];
}
if(mid!=-)cout<<char(mid+'a');
for(int i=s.size()-;i>=;i-=)
{
if(s[i]==mid+'a')i--,mid=-;
if(i>=)cout<<s[i];
}
cout<<endl;return ;
}
600D - Area of Two Circles' Intersection 20171111 20180831
一道计算几何模板题,当年没有模板的时候被卡精度卡成SB,结果发现把输出小数位数减少到6位就过了...前两天测试学长模板的时候直接秒掉了【论模板的重要性】
附上当年蠢得一比的代码
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const long double pi=acos(-1.0);
struct Circle{long double x,y,r;}c1,c2;
double ans;
void print(){printf("%.6lf\n",ans);}
int main()
{
cin>>c1.x>>c1.y>>c1.r>>c2.x>>c2.y>>c2.r;
long double dis=pow(pow(c1.x-c2.x,)+pow(c1.y-c2.y,),0.5);
if(c1.r+c2.r<=dis)return ans=,print(),;
if(c1.r-c2.r>=dis)return ans=pi*c2.r*c2.r,print(),;
if(c2.r-c1.r>=dis)return ans=pi*c1.r*c1.r,print(),;
long double angle1=*acos((c1.r*c1.r+dis*dis-c2.r*c2.r)/(*dis*c1.r));
long double angle2=*acos((c2.r*c2.r+dis*dis-c1.r*c1.r)/(*dis*c2.r));
long double s1=c1.r*c1.r*angle1/,s2=c2.r*c2.r*angle2/;
long double t1=sin(angle1)*c1.r*c1.r/,t2=sin(angle2)*c2.r*c2.r/;
ans=s1-t1+s2-t2,print();
return ;
}
600E - Lomsat gelral 20180902
启发式合并,和Codeforces 375D的做法类似,直接套用了之前的代码魔改一下就过了_(:з」∠)_
#include<bits/stdc++.h>
using namespace std;
#define N 100001
#define LL long long
LL ans[N];
int n,x,y,c[N];
vector<int>d[N];
map<int,LL>cnt[N],f[N];
void dfs(int cur,int pre)
{
cnt[cur][c[cur]]=,f[cur][]=c[cur];
for(auto nxt:d[cur])if(nxt!=pre)
{
dfs(nxt,cur);
if(cnt[nxt].size()>cnt[cur].size())
cnt[cur].swap(cnt[nxt]),f[cur].swap(f[nxt]);
for(auto x:cnt[nxt])
{
int y=cnt[cur][x.first];
cnt[cur][x.first]+=x.second;
for(int i=y+;i<=y+x.second;i++)
f[cur][i]+=x.first;
}
}
ans[cur]=(*f[cur].rbegin()).second;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&c[i]);
for(int i=;i<=n;i++)
scanf("%d%d",&x,&y),
d[x].push_back(y),
d[y].push_back(x);
dfs(,);
for(LL i=;i<=n;i++)
printf("%I64d%c",ans[i],i<n?' ':'\n');
return ;
}
600F - Edge coloring of bipartite graph 20180902
显然颜色种数是各顶点度数的最大值,下面给出一种构造方法
每次读入一条边时,分别查找该边的两顶点 u,v 的第一个未被用过的颜色,设其为c1,c2 。若c1==c2,则直接染色,否则由于v这边c1已经被占用,我们需要查找到与v共享颜色c1的点w,并将v与w之间的边改为颜色c2,这样u与v之间就可以连上一条颜色为c1的边了。在改边[v,w]的颜色时,也可能会出现w这边c2已经被占用的情况,这时就需要递归进行操作(类似于匈牙利算法的做法)。显然这样做的复杂度最大是O(n),那么整个程序的时间复杂度就是O(mn)
#include<bits/stdc++.h>
using namespace std;
#define N 2001
#define M 100001
struct rua{int v,id;};
int a,b,m,u,v,ans,x[N][N],f[N][N],c[M];
void dfs(int u,int v,int c1,int c2)
{
int w=x[v][c1];
x[v][c1]=u,x[u][c1]=v;
if(w)dfs(v,w,c2,c1);
else x[v][c2]=;
}
int main()
{
scanf("%d%d%d",&a,&b,&m);
for(int i=;i<=m;i++)
{
scanf("%d%d",&u,&v),v+=a;
f[u][v]=f[v][u]=i;
int c1=,c2=;
while(x[u][c1])c1++;
while(x[v][c2])c2++;
if(c1==c2)x[u][c1]=v,x[v][c2]=u;
else dfs(u,v,c1,c2);
ans=max(ans,max(c1,c2));
}
for(int i=;i<=a;i++)
for(int j=;j<=ans;j++)
if(x[i][j])c[f[i][x[i][j]]]=j;
printf("%d\n",ans);
for(int i=;i<=m;i++)
printf("%d%c",c[i],i<m?' ':'\n');
return ;
}
Educational Codeforces Round 2的更多相关文章
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
- Educational Codeforces Round 9
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
随机推荐
- 使用 vscode + chrome debuger断点调试 Vue 程序
总体参考:https://cn.vuejs.org/v2/cookbook/debugging-in-vscode.html 注意点: 1.修改 source-map 2.设置 webRoot 的路径 ...
- wordpress引入文件
引入顶部 <?php get_header(); ?> 引入侧栏 <?php get_sidebar(); ?> 引入底部 <?php get_footer(); ?&g ...
- Unity的Input输入
Unity中的输入管理器由Input类进行操控.官方文档地址:https://docs.unity3d.com/ScriptReference/Input.html 中文翻译的话可以在这里:http: ...
- Dubbo接口压测
在每年的双十一大促之前,除了全链路压测,还需要各个业务方对自己业务提供的核心接口进行单接口压测,以评判系统的稳定性和承压能力. 一.准备工作 环境准备:确保应用性能环境(perf)正常可用 压测接口梳 ...
- lsof 查看文件被哪个进程占用
lsof 是什么意思? 答: list open files 查看某个文件被哪些进程在读写 lsof 文件名 查看某个进程打开了哪些文件lsof –c 进程名lsof –p 进程号 lsof用法小全 ...
- sqlite基础
常用命令 sqlite3提供的特殊命令, 以.开头: .help: 帮助 .databases: 列出数据库 .tables: 列出表名 .open dbname: 打开数据库 .save dbnam ...
- 使用 TRESTClient 与 TRESTRequest 作为 HTTP Client(转)
使用 TRESTClient 与 TRESTRequest 作为 HTTP Client 转自:http://www.cnblogs.com/dennieschang/p/6966403.html ...
- linux驱动工程面试必问知识点
linux内核原理面试必问(由易到难) 简单型 1:linux中内核空间及用户空间的区别?用户空间与内核通信方式有哪些? 2:linux中内存划分及如何使用?虚拟地址及物理地址的概念及彼此之间的转化, ...
- 使用PIP扩展BTARN
下载安装部署 从GS1 US RosettaNet下载相应的PIP文件  新建BizTalk解决方案并设置签名 添加->现有项(C:\Program Files (x86)\Microsoft ...
- elastic search query & filter & query_string
一.基本概念 1.query时,如何指定返回哪些字段 希望返回name和date字段 希望返回以location.*为前缀的字段以及date字段:不希望返回location.geolocation字段 ...