Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only)
http://codeforces.com/contest/84
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 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 unsigned long long ull;
int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
ll n;
cin>>n;
cout<<*n-n/<<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 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 unsigned long long ull; int n;
ll a[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
for(int i=;i<=n;i++) cin>>a[i];
ll ans=n;
ll co=;
for(int i=;i<n;i++){
if(a[i]==a[i+]){
co++;
}
else{
ans+=co*(co-)/;
co=;
}
}
ans+=co*(co-)/;
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 unsigned long long ull; const int N = , D = ;
int n, m, x, y, c[N], r[N], s[N];
vector<int> v[D * + ]; int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n;
int ans=;
for (int i = ; i <= n; i++){
cin>>c[i]>>r[i];
c[i] += D; s[i] = -;
for (int j = c[i] - r[i]; j <= c[i] + r[i]; j++) v[j].push_back(i);
}
cin>>m;
for (int i = ; i <= m; i++){
cin>>x>>y;
x += D;
for (auto j : v[x]) if (s[j] == -)
if (y * y + (x - c[j]) * (x - c[j]) <= r[j] * r[j]){
s[j] = i;
ans++;
}
}
cout<<ans<<endl;
for (int i = ; i <= n; i++) cout<<s[i]<<" ";
}
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 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 unsigned long long ull; ll a[];
ll n,k;
int book[];
vector<int>ans; bool erfen(ll mid){
ll sum=;
for(int i=;i<=n;i++){
sum+=min(a[i],mid);
}
if(sum>=k) return true;
return false;
} int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>k;
ll sum=;
ll Max=;
ll L,R,mid;
for(int i=;i<=n;i++){
cin>>a[i];
sum+=a[i];
Max=max(Max,a[i]);
}
if(sum<k) cout<<-<<endl;
else if(sum==k){}
else{
L=,R=Max,mid;
while(L<=R){
mid=L+R>>;
if(erfen(mid)){
R=mid-;
}
else{
L=mid+;
}
}
ll kk=R;
sum=;
for(int i=;i<=n;i++){
sum+=min(a[i],kk);
a[i]-=min(a[i],kk);
}
int flag=;
for(int i=;i<=n;i++){
if(sum>k&&a[i]>){
book[i]=;
ans.pb(i);
}
else if(a[i]>){
sum++;
a[i]--;
if(sum>k&&flag&&a[i]>=){
flag=;
ans.pb(i);
book[i]=;
}
} }
for(int i=;i<=n;i++){
if(!book[i]&&a[i]>){
book[i]=;
ans.pb(i);
}
}
for(int i=;i<ans.size();i++){
cout<<ans[i]<<" ";
}
} }
E
__builtin_popcount() 函数,计算一个数转二进制之后有几个1
一道很好的最短路的题目。
题意:求S到T的最短路径,其中,路径上不同的字母不能超过K个,且答案的字典序要最小,不存在输出-1
思路:因为K小于等于4,所以可以用状压来存放不同字母的个数。在优先队列中存放距离,路径的字符串,K和该点的下表,跑一次最短路即可。
#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<pair<int,string>,pii> ppp;
typedef unsigned long long ull; int n,m,k;
int S,T;
string s[];
set<pii>se; int dist(int a,int b){
return abs(a/m-b/m)+abs(a%m-b%m);
} int dir[][]={,,,,,-,-,}; void Dijstra(){
priority_queue<ppp,vector<ppp>,greater<ppp>>Q;
Q.push({{dist(S,T),""},{,S}});
ppp ss;
string str;
int book,pos;
int x,y,xx,yy;
while(!Q.empty()){
ss=Q.top();
Q.pop();
str=ss.first.second;
book=ss.second.first;
pos=ss.second.second;
if(!se.count({book,pos})){
se.insert({book,pos});
x=pos/m,y=pos%m;
for(int i=;i<;i++){
xx=x+dir[i][];
yy=y+dir[i][];
if(xx>=&&xx<n&&yy>=&&yy<m){
if(s[xx][yy]=='T'){
cout<<str<<endl;
exit();
}
if(__builtin_popcount(book|(<<(s[xx][yy]-'a')))<=k)
Q.push({{dist(xx*m+yy,T)+str.length()+,str+s[xx][yy]},{book|(<<(s[xx][yy]-'a')),xx*m+yy}});
}
}
}
} } int main(){
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>m>>k;
for(int i=;i<n;i++){
cin>>s[i];
for(int j=;j<m;j++){
if(s[i][j]=='S'){
S=i*m+j;
}
if(s[i][j]=='T'){
T=i*m+j;
}
}
}
Dijstra();
cout<<-<<endl;
}
Codeforces Beta Round #72 (Div. 2 Only)的更多相关文章
- 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 #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 #70 (Div. 2)
Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...
随机推荐
- charles抓包的安装,使用说明以及常见问题解决(windows)
charles抓包的安装,使用说明以及常见问题解决(windows) https://blog.csdn.net/zhangxiang_1102/article/details/77855548
- tp5中ajax方式提交表单
用ajax提交表单,迅速,快捷,实现页面无刷新提交表单. <!DOCTYPE html> <html lang="en"> <head> < ...
- javascript:控制一个元素高度始终等于浏览器高度
window.onresize = function(){ this.opHtight()} //给浏览器添加窗口大小改变事件window.onresize = function(){ this.op ...
- 黑马2018年JavaEE课程大纲
包含 黑马旅游网 企业级权限管理系统 品优购 十次方 乐优(没有,十次方级别) http://www.itheima.com/course/javaeetext.html 传智 ...
- ReactiveX 学习笔记(14)使用 RxJava2 + Retrofit2 调用 REST API
JSON : Placeholder JSON : Placeholder (https://jsonplaceholder.typicode.com/) 是一个用于测试的 REST API 网站. ...
- 【原创】逆向练习(CrackMe)
Write Up 登录的两个方法 方法1.用IDA分析 新版测试题.exe.在Strings Window中查找有一定意义的串. 从上面的窗口中,发现了CyberSwat和passwordisme这两 ...
- js版RSA算法
// RSA, a suite of routines for performing RSA public-key computations in// JavaScript.//// Requires ...
- HTML+CSS基础课程三
1.文字排版--字体 我们可以使用css样式为网页中的文字设置字体.字号.颜色等样式属性.下面我们来看一个例子,下面代码实现:为网页中的文字设置字体为宋体. body{font-family:&quo ...
- eclipse 连接数据库记录
两篇很好的文章介绍给大家: Eclipse使用JDBC方式连接SQLServer2016 通过Driver与DriverManager连接数据库 --------------------------- ...
- 使用 COM 类库创建链接桌面快捷方式
用到的 COM 类库: Windows Script Host Object Model --> Interop.IWshRuntimeLibrary.dll 示例代码: private sta ...