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 ...
随机推荐
- Vue.JS React 精彩文章汇总
JavaScript深入系列 [干货] JavaScript数组所有API全解密 [干货] 移动端:页面->手淘互动动效的探索 - IT大咖说 - 大咖干货,不再错过 [扫盲] Jonath ...
- 集合总结--ArrayList、LinkedList、HashMap
一.概述 ArrayList:数组集合. 查询.修改.新增(尾部新增)快,删除.新增(队列中间)慢,适用于查询.修改较多的场景. LinkedList:双向链表集合.查 ...
- JSOUP 乱码处理
JSOUP 支持在请求的时候,传入URL 对象,然后设置编码.如下方式才是正解,设置编码为GBK . doc = Jsoup.parse(new URL(url).openStream(), &qu ...
- MUI框架开发HTML5手机APP(二)--页面跳转传值&底部选项卡切换
概 述 JRedu 在上一篇博客中,我们学习了如何使用Hbuilder创建一个APP,同时如何使用MUI搭建属于自己的第一款APP,没有学习的同学可以戳链接学习: http://www.cnblo ...
- 积木式编程——自制app点灯
技术:51单片机.串口.蓝牙.积木式编程 概述 这里简单入门了积木式编程,做了个简易APP用来开灯关灯,当然你可以继续添加内容,可以做智能家居.遥控汽车和环境监控等等. 详细 代码下载:http: ...
- ffmpeg -i 10.wmv -c:v libx264 -c:a aac -strict -2 -f hls -hls_list_size 0 -hls_time 5 C:\fm\074\10\10.m3u8
ffmpeg -i 10.wmv -c:v libx264 -c:a aac -strict -2 -f hls -hls_list_size 0 -hls_time 5 C:\fm\074\10\1 ...
- Visual Studio 2017 - Windows应用程序打包成exe文件(2)- Advanced Installer 关于Newtonsoft.Json,LINQ to JSON的一个小demo mysql循环插入数据、生成随机数及CONCAT函数 .NET记录-获取外网IP以及判断该IP是属于网通还是电信 Guid的生成和数据修整(去除空格和小写字符)
Visual Studio 2017 - Windows应用程序打包成exe文件(2)- Advanced Installer Advanced Installer :Free for 30 da ...
- Mathematica 11.1.0 下载及注册流程
新版本注册机: http://files.cnblogs.com/files/dabaopku/Mathematica_11.1.0_Keygen.exe.zip 类似于11.0, 在控制台运行, 比 ...
- python 验证码识别示例(二) 复杂验证码识别
在这篇博文中手把手教你如何去分割验证,然后进行识别. 一:下载验证码 验证码分析,图片上有折线,验证码有数字,有英文字母大小写,分类的时候需要更多的样本,验证码的字母是彩色的,图片上有雪花等噪点,因 ...
- [k8s]k8s的控制层kubelet+docker配合调度机制(k8架构)
意外停掉一台node的kubelet,发现调度有问题,研究了下调度的细节 k8s架构 控制层- kubelet(配合节点docker工作) 数据层- kube-proxy 逻辑图: object 参考 ...