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. VC 字符串转化和分割

    原文:点击这里. 备忘:为了适用于Unicode环境,要养成使用_T()宏的习惯 1.格式化字符串 CString s;s.Format(_T("The num is %d."), ...

  2. 浅谈JSONObject与JSONArray的区别

    例如:一个json字符串如下: { "type":[{"a","1"},{"a","2"},{&qu ...

  3. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql/mysql.sock' (2)

    [root@XXX ~]# mysql -h localhost -uroot -p Enter password: ERROR (HY000): Can't connect to local MyS ...

  4. DevExpress控件TExtLookupComboBox实现多列模糊匹配输入的方法

    本方案不需要修改控件源码,是完美解决支持多列模糊匹配快速输入的最佳方案!!   1.把列的Properties属性设置为ExtLookupComboBox. Properties.Incrementa ...

  5. 模糊查询内存查询java实现

    下面说说看到的工作项目中的代码,是这个样子的,事先查询一次数据库,将查询到的整张表的数据存到内存,以后使用时不再查询数据库,而直接操作内存中的数据,这主要用于数据库中的数据比较稳定,不会轻易改变的情况 ...

  6. C语言复习:字符串和一级指针

    字符串基本操作 字符数组初始化方法 int main() {     //1 {}号法 初始化列表     //数组初始化有2种方法 默认元素个数.指定元素个数     char buf1[] = { ...

  7. U3D开发中关于脚本方面的限制-有关IOS反射和JIT的支持问题

    U3D文档中说明了,反射在IOS是支持的,除了system.reflection.emit空间内的,其它都支持.JIT是不支持的. 本质上来说即是:只要不在运行时动态生成代码的行为都支持,reflec ...

  8. How to Pronounce the Days of the Week

    How to Pronounce the Days of the Week Share Tweet Share Vocabulary study:  how to pronounce the days ...

  9. ReactiveX 学习笔记(6)条件操作符

    Conditional and Boolean Operators 本文的主题为处理 Observable 的条件和布尔操作符. 这里的 Observable 实质上是可观察的数据流. RxJava操 ...

  10. Python下HttpHTTPClient和AsyncHTTPClient

    HTTPClient 使用例子: from tornado.httpclient import HTTPClient def synchronous_fetch(url): http_client = ...