Codeforces Beta Round #79 (Div. 2 Only)

时间:2022-09-05 11:50:17

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 &num;79 &lpar;Div&period; 1 Only&rpar; B&period; 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 &num;80 &lpar;Div&period; 2 Only&rpar;【ABCD】

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

  3. Codeforces Beta Round &num;83 &lpar;Div&period; 1 Only&rpar;题解【ABCD】

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

  4. Codeforces Beta Round &num;77 &lpar;Div&period; 2 Only&rpar;

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

  5. Codeforces Beta Round &num;76 &lpar;Div&period; 2 Only&rpar;

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

  6. Codeforces Beta Round &num;75 &lpar;Div&period; 2 Only&rpar;

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

  7. Codeforces Beta Round &num;74 &lpar;Div&period; 2 Only&rpar;

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

  8. Codeforces Beta Round &num;73 &lpar;Div&period; 2 Only&rpar;

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

  9. Codeforces Beta Round &num;72 &lpar;Div&period; 2 Only&rpar;

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

随机推荐

  1. JS运算符

    JS运算符: 使用的运算符的时候不需要声明变量,运算符非变量:1.算术运算符 + - * / % (%为取余数运算符) (自增运算符++) (自减运算符 --) + 运算符作用:1.数值相加 2.字符 ...

  2. android 开发中fragment 遇到的问题

    http://yifeng.studio/2016/12/15/android-fragment-attentions/ 1.不要轻易在 fragment中引用 getactivity(); 解决方案 ...

  3. Java运行环境的配置

    Make sure you do not use the trailing semicolon: This will not work: set JAVA_HOME=C:\Program Files ...

  4. 转-JS之Window对象

    一.说明:他是JS中最大的对象,它描述的是一个浏览器窗口,一般要引用他的属性和方法时,不需要用“Window.XXX”这种形式,而是直接使用“XXX”.一个框架页面也是一个窗口. 二.Window窗口 ...

  5. vue angular 分别实现分页

    1 vue实现分页组件 paginate组件 <template> <div class="pagination-wrap" v-cloak v-if=&quot ...

  6. 一、TCP扫描技术

    一.TCP扫描技术 常用的端口扫描技术有很多种,如 TCP connect() 扫描 .TCP SYN 扫描.TCP FIN 扫描 等,网络上也有很多文章专门介绍,比如 :http://www.ant ...

  7. Oracle用imp和exp实现数据的导入和导出

    使用方法如下: Imp username/password@connect_string param=value - exp username/password@connect_string para ...

  8. spi总结

    SPI的四种模式 SPI的相位(CPHA)和极性(CPOL)分别可以为0或1,对应的4种组合构成了SPI的4种模式(mode) Mode 0:CPOL = 0,CPHA = 0 Mode 1:CPOL ...

  9. Linux上面缺少rz和sz命令

    一.centos系统没有自带rz/sz命令 yum install lrzsz 搞定! 二.对于经常使用Linux系统的人员来说,少不了将本地的文件上传到服务器或者从服务器上下载文件到本地,rz / ...

  10. 使用synergyc共享键鼠

    通常情况下我们经常同时操作两台或者多台电脑, 这样就会存在多个键盘鼠标来回切换的问题. 那么我们主要的目标就是怎么在多个电脑上共享一套键盘鼠标,而且可以轻松的来回切换呢. 网上有很多的解决方案,这里我 ...