Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only)
http://codeforces.com/contest/102
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 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<char,int> pci;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int a[][];
int v[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++) cin>>v[i];
int uu,vv;
for(int i=;i<=m;i++){
cin>>uu>>vv;
a[uu][vv]=a[vv][uu]=;
}
int ans=0x3f3f3f3f;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
for(int k=;k<=n;k++){
if(i==j||j==k||k==i) continue;
if(a[i][j]==a[j][k]&&a[j][k]==a[k][i]&&a[k][i]==){ ans=min(ans,v[i]+v[j]+v[k]);
}
}
}
}
if(ans==0x3f3f3f3f) cout<<-;
else
cout<<ans<<endl;
}
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 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<char,int> pci;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
string str;
cin>>str;
int ans=;
while(str.length()!=){
int tmp=;
for(int i=;i<str.length();i++) tmp+=str[i]-'';
ans++;
str=to_string(tmp);
}
cout<<ans<<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 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int book[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
string str;
int n;
cin>>str>>n;
for(int i=;i<str.length();i++){
book[str[i]-'a']++;
}
if(str.length()<=n) cout<<<<endl<<endl;
else{
set<char>se;
vector<pic>ve;
for(int i=;i<;i++){
ve.pb({book[i],'a'+i});
}
sort(ve.begin(),ve.end());
for(int i=;i<ve.size();i++){
if(ve[i].first<=n){
n-=ve[i].first;
se.insert(ve[i].second);
}
else{
break;
}
}
string s="";
for(int i=;i<str.length();i++){
if(se.count(str[i])) continue;
else s+=str[i];
}
set<char>ss;
for(int i=;i<s.length();i++){
ss.insert(s[i]);
}
cout<<ss.size()<<endl<<s<<endl;
}
}
D
树状数组+离散化
#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 13000005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long MOD=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n,m; map<int,int>tree; int lowbit(int x){
return x&(-x);
} void add(int x,int v){
while(x<=n+){
tree[x]=(tree[x]+v)%MOD;
x+=lowbit(x);
}
} int getsum(int x){
int ans=;
while(x){
ans=(ans+tree[x])%MOD;
x-=lowbit(x);
}
return ans;
}
vector<pii>ve; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>m;
int a,b;
for(int i=;i<=m;i++){
cin>>a>>b;
ve.pb({b+,a+});
}
sort(ve.begin(),ve.end());
add(,);
for(int i=;i<m;i++){
int s=ve[i].second,t=ve[i].first;
int tmp=getsum(t-)-getsum(s-);
tmp=(tmp%MOD+MOD)%MOD;
add(t,tmp);
}
int ans=getsum(n+)-getsum(n);
cout<<(ans%MOD+MOD)%MOD<<endl;
}
Codeforces Beta Round #79 (Div. 2 Only)的更多相关文章
- Codeforces Beta Round #79 (Div. 1 Only) B. Buses 树状数组
http://codeforces.com/contest/101/problem/B 给定一个数n,起点是0 终点是n,有m两车,每辆车是从s开去t的,我们只能从[s,s+1,s+2....t-1 ...
- 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 #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> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
随机推荐
- addEventListener 的事件冒泡
语法 target.addEventListener(type, listener, useCapture); target 文档节点.document.window 或 XMLHttpRequest ...
- 【开发工具】 JEECG_3.7新版开发工具
链接:http://pan.baidu.com/s/1gfthmAf 密码:2yfv
- day13-文件操作
1.打开与关闭 1.1.open() close()我们使用 open() 函数打开文件.这个函数将返回一个文件对象,我们对文件的读写都将使用这个对象.open() 函数需要三个参数,第一个参数是文件 ...
- Mac 命令行,自定义命令
例如自定义命令 gotoXFolder, 直接进入XFolder文件夹, XFolder地址为~/abc/def/Xfolder 步骤: 1. 在home文件夹下创建.profile文件 在.prof ...
- 安装安卓SDK和JDK的简便方法
直接在VS的安装程序里选:使用.NET的移动开发,其中就包括了安卓SDK,JAVA SE等 另外:自己手动安装SDK时,不要选模拟器相关的东西,太大了,如果每个版本都选,安装下来上100G以上
- mysql 授权命令
MySQL 数据库赋予用户权限操作表 MySQL清空数据库的操作:truncate table tablename; MySQL 赋予用户权限命令的简单格式可概括为:grant 权限 on 数据库 ...
- 转: python requests的安装与简单运用
requests是Python的一个HTTP客户端库,跟urllib,urllib2类似,那为什么要用requests而不用urllib2呢? 官方文档中是这样说明的: python的标准库urlli ...
- python异常处理方法
异常是指程序中的例外.违例情况,比如序列的下标越界.打开不存在的文件.空引用异常等.通过捕获异常并进行正确处理,可以提高程序的健壮性.如果没有代码处理异常,Python解释器将输出相关异常信息并终止程 ...
- 23.week4
调通了 剩下的就是核心的部分
- 怎么在idea中新建package包,只有directory选项
http://blog.csdn.net/liyanlei5858/article/details/77320063