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 ...
随机推荐
- 微信小程序WebSocket报错:Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received
Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was ...
- 【jQuery Demo】图片切换效果整理
图片的切换效果有很多,比较常见的有水平滚动.垂直滚动.淡入淡出等.我们接下来一一实现这些效果. 1.水平滚动 1) 我们先来实现HTML页面,代码很简单: <div id="conta ...
- git中提示 please tell me who you are
提示也就是需要你登录一下,确认你的身份,但是不要按照其提示输入,先输入命令git config user.name “username”,换行输入git config user.email “emai ...
- IDEA创建多个模块MavenSpringBoot项目
最近在学习springboot,先从创建项目开始,一般项目都是一个项目下会有多个模块,这里先创建一个最简单的实例,一个项目下有一个springboot模块项目提供web服务,引用另一个java项目(相 ...
- linux服务器挂掉自动重启脚本(转)
实现原理主要是使用linux提供的crontab机制,定时查询服务器进程是否存在,如果宕机则执行我们预设的重启脚本. 首先我们要向crontab加入一个新任务 sudo crontab -e #进入编 ...
- 【python】Python的安装和配置
Python是一种计算机程序设计语言.是一种动态的.面向对象的脚本语言,最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的.大型项目的开发. Pyt ...
- MySQL 中的运算符
1.算数运算符 MySQL 支持的算术运算符包括加.减.乘.除和模运算. 运算符 作用 + 加法,获得一个或多个值的和 - 减法,从一个值中减去另一个值 * 乘法,得到两个或多个值的乘积 /,div ...
- 生成网上下载的EF项目对应的数据库
生成网上下载的EF项目对应的数据库 网上下载的用EF做的小项目,结果没有配有数据库的,用VS打开来看了一下,看到Migrations文件夹,应该可以用EF命令来生成这个数据库了 打开appsettin ...
- 为github公开项目单独设置用户名
背景: 由于在公司git的配置是公司内自己的用户id及邮箱,如果用同样的配置在github上提交公开项目,可能造成用户名及邮箱泄露,因此对于github上的项目,最好单独设置用户名,而每次在向gith ...
- mac关闭占用某个端口的进程
在启动项目的时候有时候会提示端口被占用,但是怎么都找不到那个关闭进程的地方,可以直接通过命令行关闭这个进程: 比如要关闭:8000端口的进程: 1. 查找端口进程: lsof -i: 会把所有的占用8 ...