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> ...
随机推荐
- 微信小程序插件 - 开发教程
昨天(2018.3.13),微信小程序发布了重大功能更新,支持插件的使用和开发,个人预计,不超过2个月,优质服务的插件将会如雨后春笋般涌现. 这篇文章,我将会带大家,从0开始,学习如何开发和使用插件. ...
- js记录用户访问页面和停留时间
1.setInterval setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式. setInterval(code,millisec[,"lang" ...
- django--用户认证组件
用户认证组件 用户认证组件: 功能:用session记录登录验证状态 前提:用户表:django自带的auth_user 创建超级用户: python3 manage.py createsuperus ...
- select as table
select order_time, max(sum_price) from (SELECT order, sum(price) as sum_price FROM orders group by o ...
- css 的pointer-events 属性
1.css 有好多属性,可以让你感觉到不可思议,关键是可以解决一些难以实现的问题,今天遇到一个,就是 point-enevts属性 支持 pointer-events 属性 的浏览器版本 2. 1 ...
- U3D 编辑器中sceneview下相机操作相关
前几天在项目中想要实现一个编辑器模式下的3D空间画线功能,几经周折,还是作废. 原因有:相机空间到世界空间转换问题对于Z值不清楚,U3D自定义坐标轴控制问题,射线与平面求交点不对, 一个关键问题是:编 ...
- B树、B-树、B+树、B*树的定义和区分
MySQL是基于B+树聚集索引组织表 B树 即二叉搜索树: 1.所有非叶子结点至多拥有两个儿子(Left和Right): 2.所有结点存储一个关键字: 3.非叶子结点的左指针指向小于其关键字的子树,右 ...
- b2BuoyancyController 使用浮力
package{ import Box2D.Collision.b2AABB; import Box2D.Collision.b2RayCastInput; import Box2D.Collisio ...
- 一小段测试atof的代码
#include <stdio.h> //#include <stdlib.h> double a=0; int main(int argc, char *argv[]) { ...
- Java解决小孩围圈问题
问题描述:一堆小孩围成一个圈,从第一个小孩开始数,每数到第三个便把第三个孩子删去,数到只剩一个小孩为止,并求该孩子的具体编号. 解决办法 1. package test; public class C ...