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 ...
随机推荐
- MySql的优化步骤
MySql优化的一般步骤: 1.通过show status 命令了解各种sql的执行效率 SHOW STATUS提供msyql服务器的状态信息 一般情况下,我们只需要了解以”Com”开头的指令 sho ...
- hadoop2.7.3编译,支持snappy、bzip2本地压缩
软件包: apache-ant-1.9.9-bin.tar.gz apache-maven-3.3.9-bin.tar.gz apache-tomcat-6.0.44.tar.gz CentOS-6. ...
- docker dcm4chee
The received images should show up in the UI of the Archive at http://localhost:8080/dcm4chee-arc/ui ...
- linux:gpg加密和解密
http://www.bubuko.com/infodetail-650747.html
- Linux-进程描述符 task_struct 详解
为了描述控制进程的运行,系统中存放进程的管理和控制信息的数据结构称为进程控制块 PCB(Process Control Block),它是进程实体的一部分,是操作系统中最重要的记录性数据结构.它是进程 ...
- Java基础(二)面向对象(上)
面向对象基础知识 面向对象是相对面向过程而言的 面向对象和面向过程都是一种思想 面向过程强调的是功能行为 面向对象将功能封装进对象,强调具备了功能的对象 面向对象是基于面向过程的 面向对象的特征: 封 ...
- Jquery Post提交时Content-Type的不同取值详解
四种常见的 POST 提交数据方式 我们知道,HTTP 协议是以 ASCII 码传输,建立在 TCP/IP 协议之上的应用层规范.规范把 HTTP 请求分为三个部分:状态行.请求头.消息主体.类似于下 ...
- create-react-app入门教程
Create React App是FaceBook的React团队官方出的一个构建React单页面应用的脚手架工具.它本身集成了Webpack,并配置了一系列内置的loader和默认的npm的脚本,可 ...
- Sqlmap 中绕过空格拦截的12个脚本
- 每天学点Linux-选取命令CUT和GREP
选取命令就是将一段数据经过分析后,取出我们所想要的.或者是经由分析关键词,取得我们所想要的那一行!一般来说,选取命令通常是针对一行一行的数据来进行分析的, 并不是整篇信息分析.cut cut命令可以将 ...