Educational Codeforces Round 2 个人总结A-E
Educational Codeforces Round 2
A. Extract Numbers
- 简单的模拟
bool check(string op)
{
if(op.size()==1&&op[0]=='0')
return true;
if(op.size()==0||(op[0]<'1'||op[0]>'9'))
return false;
bool st=false;
for(int i=1;i<op.size();i++)
{
if( !(op[i]>='0'&&op[i]<='9'))
st=true;
}
if(st)
return false;
else return true;
}
void solve()
{
string op; cin>>op;
string t="";
vector<string> a;
int len=op.size();
for(int i=0;i<len;i++)
{
if(op[i]!=','&&op[i]!=';')
t=t+op[i];
else
{
a.pb(t);
t="";
}
}
if(!t.empty())
a.pb(t);
if(op[op.size()-1]==','||op[op.size()-1]==';')
a.pb("");
vector<string> b,c;
for(auto it:a)
{
if(check(it))
b.pb(it);
else
c.pb(it);
}
if(b.size()!=0)
{
cout<<"\"";
len=b.size();
for(int i=0;i<len;i++)
{
cout<<b[i];
if(i!=len-1)
cout<<",";
}
cout<<"\""<<endl;
}
else
cout<<"-\n";
if(c.size()!=0)
{
cout<<"\"";
len=c.size();
for(int i=0;i<len;i++)
{
cout<<c[i];
if(i!=len-1)
cout<<",";
}
cout<<"\""<<endl;
}
else
cout<<"-\n";
return;
}
B. Queries about less or equal elements
- 二分查找板子
vector<LL> a,b;
void solve()
{
int n,m; cin>>n>>m;
for(int i=1;i<=n;i++)
{
int x; cin>>x;
a.pb(x);
}
sort(all(a));
for(int i=1;i<=m;i++)
{
int x; cin>>x;
b.pb(x);
}
for(int i=0;i<m;i++)
{
int l=0,r=n-1;
while(l<r)
{
int mid=(l+r+1)>>1;
if(a[mid]<=b[i]) l=mid;
else r=mid-1;
}
if(l==0&&b[i]<a[l])
cout<<0<<" ";
else
cout<<l+1<<" ";
}
cout<<endl;
return;
}
C. Make Palindrome
大意:输出使 s 为回文串,在操作次数最少的情况下,s 的字典序最小的字符串
根据回文串的性质,若不是回文串,即有一个或多个字母个数为奇数,为使操作次数最少,即将这些单个字母取出来,有区间 \(b[l,...r]\)从两端进行修改操作,修改操作为 \(b[r]=b[l]\) \((l<r)\)
将 \(b\) 放回 \(s\),重新构造一下就出来了
int cnt[30],n;
string op;
vector<int> b;
void solve()
{
cin>>op; n=op.size();
for(int i=0;i<n;i++)
cnt[int(op[i]-'a'+1)]++;
for(int i=1;i<=26;i++)
if(cnt[i]%2==1)
{
cnt[i]--;
b.pb(i);
}
int l=0,r=b.size()-1;
while(l<r)
b[r]=b[l],l++,r--;
for(auto it:b)
cnt[it]++;
string ans="";
char t;
for(int i=1;i<=26;i++)
{
int k=cnt[i]/2;
if(cnt[i]%2==1)
t=char('a'+i-1);
while(k--)
ans.pb(char('a'+i-1));
}
string res=ans;
reverse(all(res));
cout<<ans;
if(n%2==1)
cout<<t;
cout<<res<<endl;
return;
}
D. Area of Two Circles' Intersection
- 高中数学知识,用到了正弦定理和余弦定理,然后可以试着去做
- 这题WA34是由于精度原因,计算几何题要避免浮点数的子运算或加法
long double xa,ya,ra,xb,yb,rb;
void solve()
{
cin>>xa>>ya>>ra>>xb>>yb>>rb;
if(ra>rb)
{
swap(xa,xb);
swap(ya,yb);
swap(ra,rb);
}
long double len=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
if(ra+rb<len)
cout<<0<<endl;
else if(rb>=len+ra)
{
long double ans=ra*ra*pi;
cout<<setprecision(10)<<ans<<endl;
}
else
{
long double ang1=2.0*acos((len*len+rb*rb-ra*ra)/(2.0*len*rb));
long double ang2=2.0*acos((len*len+ra*ra-rb*rb)/(2.0*len*ra));
long double ans=ang1*rb*rb/2.0+ang2*ra*ra/2.0-0.5*sin(ang1)*rb*rb-0.5*sin(ang2)*ra*ra;
cout<<setprecision(10)<<ans<<endl;
}
return;
}
E. Lomsat gelral
是一道很入门的dsu,去找dls课看,或者oiwiki
// AC one more times
////////////////////////////////////////INCLUDE//////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
/////////////////////////////////////////DEFINE//////////////////////////////////////////
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define inf64 0x3f3f3f3f3f3f3f3f
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<long long,long long> PLL;
////////////////////////////////////////CONST////////////////////////////////////////////
const int inf = 0x3f3f3f3f;
const int maxn = 2e6 + 6;
const double eps = 1e-8;
///////////////////////////////////////FUNCTION//////////////////////////////////////////
template<typename T>
void init(T q[], int n, T val){ for (int i = 0; i <= n; i++) q[i] = val; }
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
bool cmp(int c, int d) { return c > d; }
//inline __int128 read(){__int128 x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-'){f=-1;}ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
//inline void write(__int128 x){if (x < 0){putchar('-');x = -x;}if (x > 9) write(x / 10);putchar(x % 10 + '0');}
LL get_quick_mod(LL a,LL b,LL p){ LL ans=1%p;while(b){ if(b&1) {ans=ans*a%p;} a=a*a%p,b>>=1; } return ans; }
const int mod = 1e9+7;
const int N = 1e5+10;
const int M = 1e6+10;
int n,c[N],sz[N],big[N],id[N],l[N],r[N],tot;
vector<int> e[N];
LL cnt[N],maxcnt,sumcnt,ans[N];
void dfs1(int u,int fa)
{
l[u]=++tot;
id[tot]=u;
sz[u]=1;
big[u]=-1;
for(int v:e[u])
{
if(v==fa) continue;
dfs1(v,u);
sz[u]+=sz[v];
if(big[u]==-1||sz[v]>sz[big[u]])
big[u]=v;
}
r[u]=tot;
}
void add(int x)
{
x=c[x];
cnt[x]++;
if(cnt[x]>maxcnt) maxcnt=cnt[x],sumcnt=0;
if(cnt[x]==maxcnt) sumcnt+=x;
}
void del(int x)
{
x=c[x];
cnt[x]--;
}
void dfs2(int u,int fa,bool st)
{
for(int v:e[u])
if(v!=fa&&v!=big[u])
dfs2(v,u,false);
if(big[u]!=-1)
dfs2(big[u],u,true);
for(int v:e[u])
{
if(v!=fa&&v!=big[u])
for(int x=l[v];x<=r[v];x++)
add(id[x]);
}
add(u);
ans[u]=sumcnt;
if(!st)
{
maxcnt=0;sumcnt=0;
for(int x=l[u];x<=r[u];x++)
del(id[x]);
}
}
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>c[i];
for(int i=1;i<n;i++)
{
int u,v; cin>>u>>v;
e[u].pb(v); e[v].pb(u);
}
dfs1(1,0);
dfs2(1,0,false);
for(int i=1;i<=n;i++)
cout<<ans[i]<<" ";
cout<<endl;
return;
}
int main()
{
std::ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr);
// 特殊输入 请注释上方,如__int128等
int TC = 1;
//cin >> TC;
for(int tc = 1; tc <= TC; tc++)
{
//cout << "Case #" << tc << ": ";
solve();
}
return 0;
}
Educational Codeforces Round 2 个人总结A-E的更多相关文章
- [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 ...
随机推荐
- docker 操作常用命令
镜像 #以tomcat为基础镜像创建一个容器,容器名为my-tomcat #拉取tomcat最新镜像,实际生产中,docker pull 这一步可以省略,docker run的时候会自己去拉取. do ...
- 把linux云服务器上的文件放到本地电脑windows上-----secureCRT
1.本地电脑需要安装SecureCRT 2.在secureCRT上登录云端服务器,右键点击云端服务器上方的ip地址,选择"connect SFTP session" 3.在SFTP ...
- vim重复、删除、复制、粘贴命令
0.选中 V+(上.下键) 表示选中 1.删除 1.输入10x,删除10个连续字符 2.输入3dd,将会删除3行文本 在普通模式下,你还可以使用dw或者daw(delete a word)删除一 ...
- zerotier的planet服务器(根服务器)-搭建教程
应用场景介绍: 利用阿里云服务器,搭建根服务器,把不同局域网打通,实现内网穿透,远程控制. 准备工具: 1.服务端:云服务器(有公网IP)Centos 7.6 2.客户端: 工控机(或者家里电脑 ...
- curl:(6) Could not resolve host: baidu.com; Unknown error
问题描述 有段时间没操作CentOS了,然后启动Virtualbox中的CentOS之后,发现网络不通,ping baidu.com 出现错误 curl:(6) Could not resolve h ...
- Flutter statecontroller.update(MaterialState.disabled,false)无效
因为中间会调用 void initStatesController() { if (widget.statesController == null) { internalStatesControlle ...
- vue项目运行出现warnings potentially fixable with the `--fix` option的报错问题
vue-cil3 运行报错 warnings potentially fixable with the `--fix` option. 解决办法:"lint": "vue ...
- 写一个PHP单例模式
1 <?php 2 /** 3 * Created by PhpStorm. 5 * Date: 2019/1/29 6 * Time: 17:44 7 */ 8 9 namespace App ...
- P1062 [NOIP2006 普及组] 数列 题解
目录 题目 思路 code 题目 P1062 [NOIP2006 普及组] 数列https://www.luogu.com.cn/problem/P1062 思路 先把 N 转换成 2 进制,再把这个 ...
- Software--EB--Project 身份验证
2018-01-09 16:57:51 身份验证服务 应该有两种形式得身份验证机制: 1. 在其他网站上又 Web 账号得顾客在注册或登陆到该网站时候应该能够使用这些账号. 2.没有的顾客或者希望新 ...