Codeforces Beta Round #57 (Div. 2)

http://codeforces.com/contest/61

A

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; string s1,s2; int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>s1>>s2;
rep(i,,s1.length()){
if(s1[i]==s2[i]){
cout<<;
}
else cout<<;
}
}

B

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; string s[];
map<string,int>mp; int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
string str;
rep(i,,){
s[i]="";
cin>>str;
rep(j,,str.length()){
if(str[j]>='A'&&str[j]<='Z') str[j]+=;
if(str[j]>='a'&&str[j]<='z') s[i]+=str[j];
}
}
int n;
cin>>n;
string ss;
mp[s[]]=,mp[s[]]=,mp[s[]]=;
mp[s[]+s[]]=;mp[s[]+s[]]=;mp[s[]+s[]]=;mp[s[]+s[]]=;mp[s[]+s[]]=;mp[s[]+s[]]=;
mp[s[]+s[]+s[]]=;mp[s[]+s[]+s[]]=;mp[s[]+s[]+s[]]=;mp[s[]+s[]+s[]]=;mp[s[]+s[]+s[]]=;mp[s[]+s[]+s[]]=;
while(n--){
cin>>str;
ss="";
rep(i,,str.length()){
if(str[i]>='A'&&str[i]<='Z') str[i]+=;
if(str[i]>='a'&&str[i]<='z') ss+=str[i];
}
if(mp[ss]) cout<<"ACC"<<endl;
else cout<<"WA"<<endl;
}
}

C

进制模拟

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; string a[]={"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
int v[]={,,,,,,,,,,,,};
string val[]; string roman(int n) {
string ret="";
for(int i=;i<;i++)
while(n>=v[i]) {
n-=v[i];
ret += a[i];
}
return ret;
}
void pre() {
for(int i=;i<=;i++)
val[i] = roman(i);
} char c[], B[];
int A; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
pre();
cin>>A>>B>>c;
long long v = ;
for(int i=;c[i];i++) {
v=v*A + (c[i]>='A'? c[i]-'A'+: c[i]-'');
}
if(B[]=='R') cout<<val[v].c_str()<<endl;
else {
char d[];
int dn=, base = atoi(B);
if(v==) {
d[dn++]=;
}
while(v>) {
d[dn++]=v%base;
v/=base;
}
while(dn-->) cout<<char(d[dn]>=? d[dn]-+'A': d[dn]+'');
cout<<endl;
}
}

D

通过模拟找规律可以发现,最短距离为所有的距离之和*2减去根结点下的最长链

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000005
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int n;
vector<pair<int,ll> >ve[]; int dfs(int pos,int pre){
ll Max=;
ll tmp;
ll now;
rep(i,,ve[pos].size()){
if(ve[pos][i].first!=pre){
now=ve[pos][i].second;
tmp=dfs(ve[pos][i].first,pos);
if(tmp+now>Max){
Max=tmp+now;
}
}
}
return Max;
} int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
int u,v;
ll w;
ll sum=;
rep(i,,n){
cin>>u>>v>>w;
sum+=w;
ve[u].pb(make_pair(v,w));
ve[v].pb(make_pair(u,w));
}
sum+=sum;
int Max=;
ll tmp;
rep(i,,ve[].size()){
tmp=dfs(ve[][i].first,);
if(tmp+ve[][i].second>Max){
Max=tmp+ve[][i].second;
}
}
cout<<sum-Max<<endl;
}

E

找三元祖,问前面比a[i]大且后面比a[i]小的三元组有多少个

直接上树状树组,离散化后枚举每个点,找出前面比它大的数,然后乘上后面比它小的数即可,会爆int

 #include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 1000006
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef unsigned long long ull; int tree[maxn]; int lowbit(int x){
return x&(-x);
} void update(int x){
while(x<maxn){
tree[x]+=;
x+=lowbit(x);
}
} int query(int x){
int ans=;
while(x){
ans+=tree[x];
x-=lowbit(x);
}
return ans;
} int a[maxn];
int n;
vector<int>ve; int getpos(int x){
return lower_bound(ve.begin(),ve.end(),x)-ve.begin()+;
} ll pre[maxn]; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
rep(i,,n+){
cin>>a[i];
ve.pb(a[i]);
}
sort(ve.begin(),ve.end());
ve.erase(unique(ve.begin(),ve.end()),ve.end());
int pos;
update(getpos(a[]));
ll ans=;
rep(i,,n){
pos=getpos(a[i]);
pre[i]=query(maxn-)-query(pos);
// cout<<query(maxn-1)<<" "<<query(pos)<<endl;
update(pos);
///
// cout<<pre[i]<<" "<<((n-i)-(n-pos-pre[i]))<<endl;
ans+=pre[i]*(-i+pos+pre[i]);
}
cout<<ans<<endl;
}

Codeforces Beta Round #57 (Div. 2)的更多相关文章

  1. Codeforces Beta Round #57 (Div. 2) A,B,C,D,E

    A. Ultra-Fast Mathematician time limit per test 2 seconds memory limit per test 256 megabytes input ...

  2. Codeforces Beta Round #57 (Div. 2) E. Enemy is weak

    求满足条件的三元组的个数,可以转换求一元组和二元组组成的满足条件的三元组的个数,且对于(x),(y,z),x > y,且x出现的p_x < p_y. x可直接枚举O(n),此时需要往后查询 ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  5. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  6. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  9. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

随机推荐

  1. CKEditor 5

    1.官网 https://ckeditor.com/ckeditor-5/download/ 2.

  2. 让linux每天定时备份MySQL数据库并删除五天前的备份文件

    MYSQL定期备份是一项重要的工作,但人工操作太繁琐,也难避免有所疏漏,使用下面的方法即可让系统定期备份数据.利用系统crontab来定时执行备份文件,按日期对备份结果进行保存,达到备份的目的. 1. ...

  3. PHP和Nginx 文件上传大小限制问题解决方法

    对于nginx+php的一些网站,上传文件大小会受到多个方面的限制,一个是nginx本身的限制,限制了客户端上传文件的大小,一个是php.ini文件中默认了多个地方的设置. 所以为了解决上传文件大小限 ...

  4. 机器学习进阶-图像金字塔与轮廓检测-轮廓检测 1.cv2.cvtColor(图像颜色转换) 2.cv2.findContours(找出图像的轮廓) 3.cv2.drawContours(画出图像轮廓) 4.cv2.contourArea(轮廓面积) 5.cv2.arcLength(轮廓周长) 6.cv2.aprroxPloyDP(获得轮廓近似) 7.cv2.boudingrect(外接圆)..

    1. cv2.cvtcolor(img, cv2.COLOR_BGR2GRAY) # 将彩色图转换为灰度图 参数说明: img表示输入的图片, cv2.COLOR_BGR2GRAY表示颜色的变换形式 ...

  5. 自动配置IE代理脚本

    http://www.cnblogs.com/ttyp/archive/2005/11/18/279124.html

  6. Linux查看当前系统的发行版信息

    lsb_release命令用来查看当前系统的发行版信息(prints certain LSB (Linux Standard Base) and Distribution information.). ...

  7. css下拉导航栏代码

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. Linux命令:chmod

    https://baijiahao.baidu.com/s?id=1616750933810368135&wfr=spider&for=pc

  9. Android Studio3.1.2编译时Java Compiler出错:Warning: Failed to parse host proxy3.bj...

    删除gradle.properties中的代理设置... #移除下面配置systemProp.http.proxyHost=proxy3.bj.petrochina systemProp.http.p ...

  10. 函数传参传的是啥的思考【java Python】

    今天看<java 核心 卷1>的时候,作者提到了函数传参的问题,他提到,java传参,传的是值,而不是引用,然后,函数将要传的实参的值(如果实参是基本数据类型,那么就是值.如果实参是对象, ...