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)的更多相关文章

  1. 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 ...

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

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

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

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

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

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

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

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

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

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

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

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

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

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

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

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

随机推荐

  1. centos 7 端口

    查看端口是否占用 netstat -tlnp|grep 8080 查看已经开放的端口 firewall-cmd --zone=public --list-ports 增加开放端口 firewall-c ...

  2. easyui datagrid取消点击行的选中事件

    http://www.jeasyui.com/demo/main/index.php?plugin=DataGrid&theme=material&dir=ltr&pitem= ...

  3. 支持向量机通俗导论(理解SVM的三层境界)(ZT)

    支持向量机通俗导论(理解SVM的三层境界) 原文:http://blog.csdn.net/v_JULY_v/article/details/7624837 作者:July .致谢:pluskid.白 ...

  4. ReactiveX 学习笔记(14)使用 RxJava2 + Retrofit2 调用 REST API

    JSON : Placeholder JSON : Placeholder (https://jsonplaceholder.typicode.com/) 是一个用于测试的 REST API 网站. ...

  5. python 学习笔记之@property

    今天学习python类看到 @property 的用法觉得很新奇,就自己尝试了很久,刚开始不明白,后来终于明白了点 其实总结一句话就是, @property 把类中的方法调用方式改变成当成属性属性调用 ...

  6. 遍历DOM树,获取子节点

    获取子节点的方法有:  方法  说明  children()  选取子节点,可以带过滤参数.但只能选择子节点,不能选择孙子节点.  find()  选取子节点,可以带过滤参数.可以选择子节点及孙子节点 ...

  7. 如何使用JDBC连接Mysql数据库

    //java类名BaseDaopublic class BaseDao {    private Connection conn = null; // 声明Connection对象,Connectio ...

  8. delphi Drag and Drop sample 鼠标拖放操作实例

    Drag and Drop is a common operation that makes the interface user friendly: a user can drag/drop inf ...

  9. ArcMap导入图层出现General function failure问题 [转]

      ArcMap导入图层出现General function failure问题 [转] Link: http://www.cnblogs.com/angelx/p/3391967.html 问题描述 ...

  10. SQL Server GROUP BY 后 拼接 字符串

    原文地址:https://blog.csdn.net/u010673842/article/details/79637618 select ID, ,,'') from class a group b ...