Codeforces Beta Round #75 (Div. 2 Only)
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)的更多相关文章
- 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 ...
- 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 ...
- Codeforces Beta Round #67 (Div. 2)
Codeforces Beta Round #67 (Div. 2) http://codeforces.com/contest/75 A #include<bits/stdc++.h> ...
- 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 #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
随机推荐
- sql server的缺陷 将截断字符串或二进制数据 哪个字段
将截断字符串或二进制数据 哪个字段 消息 8152,级别 16,状态 14,第 2 行将截断字符串或二进制数据. sql server2000 sql server2014 也不能直接提示出哪个字段的 ...
- DOS 格式化日期时间输出
if "%date:~5,2%" lss "10" (set mm=0%date:~6,1%) else (set mm=%date:~5,2%)if &quo ...
- Leetcode 题解 First Missing Positive
Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] ...
- 尚硅谷redis学习8-事务
是什么? 能干嘛? 常用命令 案例说明 1.正常执行 2.放弃事务 3.全部放弃(全体连坐) 4.只抛弃错误(冤头债主) 5.watch监控 悲观锁 悲观锁(Pessimistic Lock), 顾名 ...
- echarts.js制作中国地图
一.准备 1. 打开sublime,新建一个echarts文件夹,新建echarts.html文件 2. 在echarts.html文件中,为ECharts准备一个Dom(id是china-map ...
- django 运行脚本
转自:https://segmentfault.com/a/1190000006752130 runscript 命令会首先检查每个 app 下的 scripts 目录,如果找到对应名字的脚本就会执行 ...
- powerdesiner技巧
1.name和code同步问题和name成comments http://blog.csdn.net/huang_xw/article/details/5722981 2.连接数据库
- thymeleaf 字面量
- Nginx深度优化
简介 1.隐藏版本号2.修改Nginx用户与组3.配置Nginx网页缓存时间4.实现Nginx的日志切割5.配置Nginx实现连接超时6.更改进程数7.配置Nginx实现网页压缩功能8.配置Nginx ...
- 根据获取的窗口句柄遍历窗口Edit控件
网上说遍历窗口控件有两种方法: 1),使用EnumChildWindows,没有深究, 学习网址如下:http://blog.sina.com.cn/s/blog_60ac1c4b010116 ...