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

  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. 自动化:web网页理解

    一.网页成分 网页由以下三部分组成 HTML: HTML 教程 (w3school.com.cn) 1.标记语言,网页的主体,不会变化 2.只会提示,不会报错 CSS: 1.标记语言,用来修饰HTML ...

  2. (python)json 格式文件

    Json 数据格式: python 的内置模块: json 格式数据声明只能有一层顶级层(字典格式,可以是任意对象,如字符串,列表等,但实际工作中一般为字典对象,) json 对象本质是一个字符串对象 ...

  3. 《Rust权威指南》学习笔记——8.通用集合类型

    Rust通用集合类型 动态数组Vec 字符串String 和&str 哈希映射HashMap

  4. MySQL学习日志(建设中)

    1.前期准备 1.1软件需求 mysql8.0 Connector/J 8.0.31 workbench(懒得放链接自行百度吧) 一定不要下5.5或更低版本的,我折磨了宝贵的一上午,低版本bug很多, ...

  5. java中post发送json格式数据

    /** * 发送post请求 * @param URL 数据发送地址 * @param json json格式数据内容 * @param headParams 请求头内容 * @return 请求结果 ...

  6. springsecurity maven 打包后,404错误。maven 打包后,加载内置的xml文件

    404错误,解决的办法,主要是pom文件 <build> <resources> <resource> <directory>src/main/reso ...

  7. CentOS7安装GLPI资产管理系统

    1.安装配置docker-ce此步骤不在此赘述 2.启动配置MySQL容器 mkdir -p /opt/mysql5.7/{data,conf} docker pull mysql:5.7.31 do ...

  8. 卡片式UI设计详细指南,先收好这8条!

    今天为大家分享的是「卡片设计」. 卡片是产品中常见的设计组件之一.通过卡片,可以将不同的内容分层次组合在一起.卡片式设计自带简约和易用的属性,能让页面看起来更有秩序感. 卡片作为常用的UI组件,通常由 ...

  9. css 动画基础配置说明

    span { animation: roll 0.8s; animation-fill-mode: forwards; // 执行一次,  infinity // 执行多次 animation-tim ...

  10. keypress和keydown的区别

    keypress不识别功能键,比如ctrl,alt,shift,上下左右.keypress返回的ascII码区分大小写.输入小写a返回97,输入大写A返回65. keydown识别.keydown返回 ...