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

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

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

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

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

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

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

  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 #70 (Div. 2)

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

随机推荐

  1. 【转】Intro to ShockBurst/Enhanced ShockBurst

    原地址https://devzone.nordicsemi.com/b/blog/posts/intro-to-shockburstenhanced-shockburst Wireless PC ac ...

  2. ABAP-多线程处理

    *&---------------------------------------------------------------------* *& Report ZRICO_TES ...

  3. VB-串口通信详解

    转载:https://blog.csdn.net/dongyue786/article/details/8177047 MSComm 控件通过串行端口传输和接收数据,为应用程序提供串行通讯功能.MSC ...

  4. C# 利用反射调用类下的方法

    namespace TestReflection { public partial class Form1 : Form { public Form1() { InitializeComponent( ...

  5. 尚硅谷redis学习8-事务

    是什么? 能干嘛? 常用命令 案例说明 1.正常执行 2.放弃事务 3.全部放弃(全体连坐) 4.只抛弃错误(冤头债主) 5.watch监控 悲观锁 悲观锁(Pessimistic Lock), 顾名 ...

  6. 动态修改属性设置 easyUI

    if(条件){  $("#area").combobox({ required:false }); }else{ $("#area").combobox({ r ...

  7. web前端基础知识!

    [HTML文档的基本结构和语法][基本结构]: <HTML> HTML 文件开始 <HEAD> HTML 文件的头部开始 <title> 网页的标题</tit ...

  8. SPSS-生存分析

    生存分析 定义:一些医学事件所经历的时间:从开始观察到事件发生的时间,不是短期内可以明确判断的.针对这类生存资料的分析方法叫生存分析.生存分析的基本概念1.终点事件终点事件outcome event: ...

  9. vue 异步请求

    摘自 ECMAScript 6 简介: 大家习惯将 ECMAScript 6.0 简称为 ES6,它是 Javascript 语言的下一代标准,它的目标,是使得 Javascript 语言可以用来编写 ...

  10. php常见排序

    public function actionQuickSort(){ $arr = ['5', '4', '3', '2', '1', '0']; $quickRes = $this->quic ...