Codeforces Beta Round #57 (Div. 2)
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)的更多相关文章
- 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 ...
- Codeforces Beta Round #57 (Div. 2) E. Enemy is weak
求满足条件的三元组的个数,可以转换求一元组和二元组组成的满足条件的三元组的个数,且对于(x),(y,z),x > y,且x出现的p_x < p_y. x可直接枚举O(n),此时需要往后查询 ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
随机推荐
- MVC基于角色权限控制--权限过滤
用户访问服务器实际上就是访问控制器下的方法,因此在权限控制就是控制器方法的访问权限 为了方便控制,我们可以建立一个基类控制器(BaseController),让需要的控制器继承这个控制器即可,在Bas ...
- [转] golang socket
server.go package main import ( "net" "fmt" "io/ioutil" "time&quo ...
- CSS 点击事件
:active 伪类向激活(在鼠标点击与释放之间发生的事件)的元素添加特殊的样式. 这个伪类应用于处于激活状态的元素.最常见的例子就是在 HTML 文档中点击一个超链接:在鼠标按钮按下期间,这个链接是 ...
- 分布式ID生成学习
唯一 && 趋势有序 数据库auto_increment,多个写库时,每个写库不同的初始值和相同的步长(A(0,2)B(1,2)) 缺点:非绝对递增,写库压力大 DB只保存序列最大值, ...
- git 常用的命令总结
下载gitlab上的代码: git clone ssh://git@47.xx.xx.xx:4xx/xxx.git 查看git代码状态: git status 不提交的代码文件: git checko ...
- 【转】【java】论integer是地址传递还是值传递
转自:http://www.tuicool.com/articles/AraaQbZ 论integer是地址传递还是值传递 Integer 作为传参的时候是地址传递 , 可以参考如下例子,在程序刚启动 ...
- python模块os
一.os模块概述 Python os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.(一语中的) 二.常用方法 1.os.name 输出字符串指示正在使用的平台 ...
- 虚拟机安装VMware tools
选择虚拟机菜单栏--安装VMware tools 2 然后在CentOS系统中弹出的VMware tools窗口中 右击VMwaretools-9.6.0-1294478.tar.gz 解压缩到 3 ...
- python实现Excel删除特定行、拷贝指定行操作
工作中遇到的,本来用VBA写的,操作很慢,尝试用Python实现, 任务需求: 从原始的两张表中拷贝行到五张表中,如下表所示: source1和source2是一样的格式: one t ...
- genymotion使用学习
1 安装 直接去其官网(https://www.genymotion.com/#!/download)下载安装包安装即可,安装中会附带安装VirtualBox. 2 注册 必须使用帐号登录后,方可下载 ...