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的更多相关文章

  1. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  2. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  3. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  4. [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 ...

  5. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  6. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  7. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  8. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. 对Android中的堆栈的理解(Stack)

      版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Ln_ZooFa/article/details/50337529 堆栈空间分配 栈(操作系统): ...

  2. 调用 LoadLibraryEx 失败,在 ISAPI 筛选器 "C:\Windows\Microsoft.NET\Framework\v4.0.30319\\aspnet_filter.dll" 上

    开始 -> 运行 -> inetmgr -> 应用程序池 -> 找到 我的网站对象的 程序池 -> 右键 -> 高级设置 -> 启用32位应用程序 由 fal ...

  3. SpringBoot注解大全(转)

    原文链接:[springBoot系列]--springBoot注解大全 一.注解(annotations)列表 @SpringBootApplication:包含了@ComponentScan.@Co ...

  4. kettle 6.1 通过JS脚本与SwitchCase结合实现目标步骤选择

    场景: 判断抽取的数据在目标库中是否已经存在(同一个病人是否已经存在治疗方案号): 1.若不存在,则GROUPROWNO=1,并Insert into 目标库   ( 判断外关联字段是否为空 ) 2. ...

  5. [Python设计模式] 第13章 造小人——建造者模式

    github地址:https://github.com/cheesezh/python_design_patterns 题目1 用程序模拟一个画小人的过程,要求小人要有头,身子,左手,右手,左脚,右脚 ...

  6. 解决Maven项目总是回跳到jdk1.5的情况的方法

    一.在pom.xml中加入: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins& ...

  7. 运维笔记10 (Linux软件的安装与管理(rpm,yum))

    概述:用rpm安装和管理软件(rpm解决依赖性),用yum安装与管理软件(yum解决依赖性). 1.linux的软件 linux能够说是一款改变时代的操作系统,可是一个操作系统再优秀假设没有好用的应用 ...

  8. reStructuredText语法简单说明

    reStructuredText 是扩展名为.rst的纯文本文件,含义为"重新构建的文本"",也被简称为:RST或reST. 官方网址: http://docutils. ...

  9. Django 用户登陆访问限制 @login_required

    #用户登陆访问限制 from django.http import HttpResponseRedirect #只有登录了才能看到页面 #设置方法一:指定特定管理员才能访问 def main(requ ...

  10. 如何修改启动jupyter的文件路径

    1.cmd 2.jupyter notebook 工作目录路径 办法二: 1.启动pycharm 2.创建一个ipynb文件 3.运行该文件---在打印结果中找到网址,在网页中打开即可正常显示