Codeforces Beta Round #75 (Div. 2 Only)

http://codeforces.com/contest/92

A

 #include<iostream>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define maxn 100005
typedef long long ll;
typedef unsigned long long ull;
const ull MOD=;
/*#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);
int n,m;
cin>>n>>m;
int i=;
while(i+<=m){
m-=i+;
i++;
if(i==n) i%=n;
}
cout<<m<<endl;
}

B

模拟+找规律

 #include<iostream>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define maxn 100005
typedef long long ll;
typedef unsigned long long ull;
const ull MOD=;
/*#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;
if(str==""){
cout<<;
return ;
}
int ans=;
for(int i=str.length()-;i>=;i--){
if(str[i]==''&&i==) break;
if(str[i]==''){
ans+=;
int l=i;
while(l>=&&str[l]==''){
str[l]='';
l--;
}
if(l>=) str[l]='';
}
else{
ans++;
} }
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 1000006
#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<char,int> pci;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ vector<int>ve[];
int book[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
string s1,s2;
cin>>s1>>s2;
int ans=;
for(int i=;i<s1.length();i++){
ve[s1[i]-'a'].pb(i);
}
int pos=-;
int x,tmp;
for(int i=;i<s2.length();i++){
x=s2[i]-'a';
if(ve[x].size()==){
cout<<-<<endl;
return ;
}
tmp=lower_bound(ve[x].begin(),ve[x].end(),pos+)-ve[x].begin();
if(tmp!=ve[x].size()){
pos=ve[x][tmp];
}
else{
ans++;
pos=lower_bound(ve[x].begin(),ve[x].end(),)-ve[x].begin();
pos=ve[x][pos];
}
// cout<<tmp<<" "<<pos<<" "<<ans<<endl;
// cout<<pos<<endl;
}
cout<<ans<<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 100005
#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<char,int> pci;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int a[maxn];
int tree[maxn<<];
int n; void push_up(int rt){
tree[rt]=min(tree[rt<<],tree[rt<<|]);
} void build(int l,int r,int rt){
if(l==r){
tree[rt]=a[l];
return;
}
int mid=l+r>>;
build(lson);
build(rson);
push_up(rt);
} int query(int L,int R,int v,int l,int r,int rt){
if(l==r&&L<=l&&R>=r){
return l;
}
int mid=l+r>>;
if(L<=mid&&tree[rt<<]<v){
return query(L,R,v,lson);
}
else if(R>mid&&tree[rt<<|]<v){
return query(L,R,v,rson);
}
return -;
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
for(int i=n;i>=;i--) cin>>a[i];
build(,n,);
int pos;
vector<int>ans;
for(int i=;i<=n;i++){
pos=query(,i,a[i],,n,);
if(pos==-) ans.pb(pos);
else ans.pb(i-pos-);
}
reverse(ans.begin(),ans.end());
for(int i=;i<ans.size();i++) cout<<ans[i]<<" ";
}

E

并查集

 #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 100005
#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<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 n,m;
int fa[]; int Find(int x){
int r=x,y;
while(x!=fa[x]) x=fa[x];
while(r!=x){
y=fa[r];
fa[r]=x;
r=y;
}
return x;
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>m;
int x,y,xx,yy;
ll ans=;
for(int i=;i<=n;i++) fa[i]=i;
for(int i=;i<m;i++){
cin>>x>>y;
xx=Find(x),yy=Find(y);
if(xx==yy){
ans=(ans+ans)%MOD;
}
else fa[xx]=yy;
cout<<ans-<<endl;
} }

Codeforces Beta Round #75 (Div. 2 Only)的更多相关文章

  1. Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树+二分

    B. Queue Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/problem/91/B Descrip ...

  2. Codeforces Beta Round #75 (Div. 1 Only) B. Queue 二分

    B. Queue Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/problem/91/B Descrip ...

  3. Codeforces Beta Round #67 (Div. 2)

    Codeforces Beta Round #67 (Div. 2) http://codeforces.com/contest/75 A #include<bits/stdc++.h> ...

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. Centos6与Centos7防火墙设置与端口开放的方法

    Centos升级到7之后,内置的防火墙已经从iptables变成了firewalld.所以,端口的开启还是要从两种情况来说明的,即iptables和firewalld.更多关于CentOs防火墙的最新 ...

  2. mingw 搭建Emscripten 环境

    mingw 环境的搭建可以参考网上很多文章,不复杂.但在搭建Emscripten 环境之前需要配置git 和python 和MSbuild.exe 还需要安装camke 默认安装之后应该是添加了 系统 ...

  3. struts2中的constant介绍之struts.objectFactory与spring的整合

    struts2提供给我们更为灵活的设计,他的很多东西都是可以手动配置的,下面介绍下他的一些 常用的constant作用和配置 struts.objectFactory这个属性用于说明Struts2的 ...

  4. vue:监听数据

    1:普通的监听: data () { return { watchNum:1, } }, watch: { watchNum(newValue, oldValue) { console.log(old ...

  5. Servlet基本_Filter

    1.概念・サーブレットフィルタとは.サーブレットやJSPの「共通の前後処理」を記述するための仕組みです.・フィルタはサーブレットやJSPの前に位置し.実行前と後に.リクエスト.レスポンスに対して任意の ...

  6. 初级java程序员-各公司技能要求

    熟悉tomcat部署和性能调试,开发常用linux 命令,有性能调优(tomcat,sql等)经验优先: 熟练使用SSH.springmvc.mybatis.Hibernate.jquery等框架,了 ...

  7. APP发行渠道

    1,安卓APP发行:google play,原名android store 2,IOS APP: apple store 3,国内各大平台,应用宝,360,小米,华为 ...

  8. Excel VBA 使用笔记

    开发工具选项卡(Developer Tab) File Tab -> Options -> Customize Ribbon -> Main Tabs -> Developer ...

  9. maven ,添加加密算法 apache commons-codec.jar 包

    在百度搜索commons-codec.jar maven  , http://mvnrepository.com/ 到 maven 库搜索 commons-codec.jar maven .你需要添加 ...

  10. winform下利用webBrowser执行javascript

    目前很多网站为了防止恶意提交表单信息,大多都采用了加密的方式对提交信息进行处理,加密处理后通过POST提交给服务器验证,这种操作一般都是用Javascipt进行加密,若是我们想要正确提交表单到网站,就 ...