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. MVC基于角色权限控制--管理角色

    管理角色分为 添加角色.删除角色.修改角色.给角色分配权限(修改角色权限) 新建RoleInfoController继承BaseController namespace CZBK.ItcastOA.W ...

  2. Linux 目录栈及目录切换

    使用 cd - (中杠)会切换到上一次的目录 cd 命令会改变目录栈 1.dirs 1)功能显示当前目录栈中的所有记录(不带参数的dirs命令显示当前目录栈中的记录) 2)语法(1)格式:dirs  ...

  3. 深度学习原理与框架-Tensorflow基本操作-mnist数据集的逻辑回归 1.tf.matmul(点乘操作) 2.tf.equal(对应位置是否相等) 3.tf.cast(将布尔类型转换为数值类型) 4.tf.argmax(返回最大值的索引) 5.tf.nn.softmax(计算softmax概率值) 6.tf.train.GradientDescentOptimizer(损失值梯度下降器)

    1. tf.matmul(X, w) # 进行点乘操作 参数说明:X,w都表示输入的数据, 2.tf.equal(x, y) # 比较两个数据对应位置的数是否相等,返回值为True,或者False 参 ...

  4. 基于官方镜像MySQL做自定义业务扩充镜像

    转自:https://www.cnblogs.com/jsonhc/p/7809571.html 首先从https://hub.docker.com/_/mysql/拉取官方镜像,如果速度缓慢,建议添 ...

  5. zabbix server配置文件参数详解

    AlertScriptsPath默认值:/usr/local/share/zabbix/alertscripts说明:告警脚本目录 AllowRoot默认值:0 说明:是否允许使用root启动,0:不 ...

  6. RabbitMQ系列教程之二:工作队列(Work Queues)(转载)

    RabbitMQ系列教程之二:工作队列(Work Queues)     今天开始RabbitMQ教程的第二讲,废话不多说,直接进入话题.   (使用.NET 客户端 进行事例演示)          ...

  7. Linux tr命令使用方法

    tr命令主要用于删除文件中控制字符或进行字符转换.本文主要介绍tr命令的基本语法和使用实例. tr基本语法 tr命令格式:tr [ -d ] [ -c ] [ -s ] [ 字符串1 ] [ 字符串2 ...

  8. TLS协议工作过程;如何应用TLS/SSL协议为WEB流量提供安全

      SSL/TLS协议的基本过程是这样的: 客户端向服务器端索要并验证公钥. 双方协商生成"对话密钥". 双方采用"对话密钥"进行加密通信.   上面过程的前两 ...

  9. 一个神奇的BUG :Failed to finalize session : INSTALL_FAILED_INVALID_APK: /data/app/vmdl99393454.tmp/10_slice__ signatures are inconsistent

    Android Studio 在Gradle编译完成后安装APK时总是失败,EventLog提示如下信息: Failed to finalize session : INSTALL_FAILED_IN ...

  10. SQL中ISNULL的问题。

    今天在写SQL代码的时候写了个 ISNULL(变量1,变量2),返回的结果居然是 "*" ,这个星号,郁闷了很久. 代码大意如下: ) declare @str2 int sele ...