A ~~

B ~~

C

对于第二种方法,我们可以任取一个换c[i]个potions,花费d[i];或者是不取,我的做法就是枚举这些情况,得到剩余的s,再尽量优的获取小的a[i];

枚举+二分

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e19+1LL;
const double Pi = acos(-1.0);
const int N = 5e5+, maxn = 1e3+, mod = 1e9+, inf = 2e9; LL n,m,k,x,s,d[N],c[N],san[N];
struct ss{
LL a,b;
}p[N],p1[N];
int check(LL T) {
LL miT = INF;
for(int i = ; i <= k+; ++i) {
LL ret = s - d[i];
if(ret < ) continue;
if(ret < san[]) {
miT = min(miT,(n-c[i])*x);
} else {
if(san[m] < ret) {
miT = min(miT,(n-c[i])*p1[m].a);
}
else {
int pos = upper_bound(san+,san+m+,ret) - san - ;
miT = min(miT,(n-c[i])*p1[pos].a);
}
}
}
if(miT <= T) return ;
else return ;
}
bool cmp(ss s1,ss s2) {
return s1.b < s2.b;
}
int main() {
scanf("%I64d%I64d%I64d%I64d%I64d",&n,&m,&k,&x,&s);
for(int i = ; i <= m; ++i) scanf("%I64d",&p[i].a);
for(int i = ; i <= m; ++i) scanf("%I64d",&p[i].b); sort(p+,p+m+,cmp);
int cnt = ;
p1[++cnt] = p[];
for(int i = ; i <= m; ++i) {
if(p[i].a >= p1[cnt].a) continue;
p1[++cnt] = p[i];
}
m = cnt;
for(int i = ; i <= m; ++i) san[i] = p1[i].b; for(int i = ; i <= k; ++i) scanf("%I64d",&c[i]);
for(int i = ; i <= k; ++i) scanf("%I64d",&d[i]);
LL l = , r = x*n;
LL ans = x * n;
while(l <= r) {
LL md = (l+r)>>;
if(check(md)) {
ans = md, r = md-;
} else l = md + ;
}
cout<<ans<<endl;
return ;
}

C

D

想要知道是否有个黑棋能不跳跃棋子一步走到白棋,白棋只有一个,我们将其8个方向第一碰到的黑棋挑出来判断黑棋行走方式是否可以到达白棋就可以了

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e19+1LL;
const double Pi = acos(-1.0);
const int N = 1e6+, maxn = 1e3+, mod = 1e9+, inf = 2e9; int n,x,y,d[N],can;
char chs[N];
int ss[][] = {-,,,-,,,,,,,-,-,,-,-,};
struct ss{int x,y;} c[],p[N];;
int go(int j,int i) {
int ok = ;
if(j == && (p[i].x > c[j].x||c[j].x==inf))c[j] = p[i],ok=;
if(j == && (p[i].y > c[j].y||c[j].y==inf))c[j] = p[i],ok=;
if(j == && (p[i].x < c[j].x||c[j].x==inf))c[j] = p[i],ok=;
if(j == && (p[i].y < c[j].y||c[j].y==inf))c[j] = p[i],ok=;
if(j == && (p[i].x < c[j].x||c[j].x==inf))c[j] = p[i],ok=;
if(j == && (p[i].x > c[j].x||c[j].x==inf))c[j] = p[i],ok=;
if(j == && (p[i].x < c[j].x||c[j].x==inf))c[j] = p[i],ok=;
if(j == && (p[i].x > c[j].x||c[j].x==inf))c[j] = p[i],ok=;
return ok;
}
int check(int j,int i) {
can = ;
int xx = ss[j][] + x;
int yy = ss[j][] + y;
if((p[i].y-y)*(xx-x) != (p[i].x-x)*(yy-y)) return ;
if((p[i].y-y)*(yy-y) < || (p[i].x-x)*(xx-x) < ) return ;
if(j > && chs[i] != 'R' ) can = ;
else if(j < && chs[i] != 'B' ) can = ;
else can = ;
return ;
}
int main() {
char ch[];
scanf("%d%d%d",&n,&x,&y);
for(int i = ; i <= n; ++i) {
scanf("%s%d%d",ch,&p[i].x,&p[i].y);
chs[i] = ch[];
}
for(int i = ; i < ; ++i) c[i].x = inf,c[i].y = inf;
for(int i = ; i <= n; ++i) {
for(int j = ; j < ; ++j) {
if(!check(j,i)||!go(j,i)) continue;
if(can) d[j] = ;
else d[j] = ;
// cout<<j<<":"<<can<<endl;
}
}
int ok = ;
for(int i = ; i < ; ++i) if(d[i]) ok = ;
if(ok) puts("YES");else puts("NO");
return ;
}

D

E

首先,对于颜色相同的且相连的点,我们将其看作一个点,那么新图就是黑白相连的树了

对于一个黑白间隔的图,最少的次数很容易算就是树直径除2,向下取整.

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double Pi = acos(-1.0);
const int N = +, maxn = 1e3+, mod = 1e9+, inf = 2e9; int n,a[N],fa[N],u[N],v[N],from,ans = -;
vector<int >G[N];
int finds(int x) {return x==fa[x]?x:fa[x]=finds(fa[x]);}
void dfs(int u,int f,int dep) {
if(dep > ans) {
ans = dep;
from = u;
}
for(int i = ; i < G[u].size(); ++i) {
int to = G[u][i];
if(to == f) continue;
dfs(to,u,dep+);
}
}
int main() {
scanf("%d",&n);
for(int i = ; i <= n; ++i) scanf("%d",&a[i]);
for(int i = ; i < n; ++i) scanf("%d%d",&u[i],&v[i]);
for(int i = ; i <= n; ++i) fa[i] = i;
for(int i = ; i < n; ++i) {
int fx = finds(u[i]);
int fy = finds(v[i]);
if(a[u[i]] == a[v[i]]) {
fa[fx] = fy;
}
}
for(int i = ; i < n; ++i) {
int fx = finds(u[i]);
int fy = finds(v[i]);
if(a[fx] != a[fy]) {
G[fx].push_back(fy);
G[fy].push_back(fx);
}
}
dfs(finds(),-,);
dfs(from,-,);
printf("%d\n",ans/);
return ;
}

E

F

观察i,j得到

  (a[i] and a[j]) +   (a[i] or a[j]) = a[i] + a[j];

我们就这样轻松得到a数组了

如何判断?

对于数组a,取出二进制下60每个数的01情况来检查这个a数组是否满足题目条件 O(N*60)

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double Pi = acos(-1.0);
const int N = +, maxn = 1e3+, mod = 1e9+, inf = 2e9;
LL a[N],n,b[N],c[N],num[N];
LL sum = ;
int main() {
scanf("%I64d",&n);
for(int i = ; i <= n; ++i) scanf("%I64d",&b[i]),sum+=b[i];
for(int i = ; i <= n; ++i) scanf("%I64d",&c[i]),sum+=c[i];
if(sum%(2LL*n)!=) {
puts("-1");
return ;
}
sum = sum/(*n);
for(int i = ; i <= n; ++i)
{
LL now = b[i]+c[i] - sum;
if(now%n!=) {
puts("-1");
return ;
}
a[i] = now/n;
}
for(int i = ; i <= n; ++i) {
LL tmp = a[i];
for(int j = ; j <= ; ++j) {
num[j]+=tmp%;
tmp/=;
}
}
for(int i = ; i <= n; ++i) {
LL tmpb = , tmpc = ;
for(int j = ; j <= ; ++j) { if((a[i]&(1LL<<j-))) tmpc += 1LL*n*(1LL<<j-);
else tmpc += 1LL*num[j]*(1LL<<j-); if(a[i]&(1LL<<j-)) tmpb += 1LL*num[j]*(1LL<<j-);
}
//cout<<tmpb<<" "<<tmpc<<endl;
if(tmpb != b[i] || tmpc != c[i]) {
puts("-1");;
return ;
}
}
for(int i = ; i <= n; ++i) cout<<a[i]<<" ";
return ;
}

f

Codeforces Round #379 (Div. 2)的更多相关文章

  1. Codeforces Round #379 (Div. 2) Analyses By Team:Red & Black

    A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lu ...

  2. Codeforces Round #379 (Div. 2) E. Anton and Tree 缩点 直径

    E. Anton and Tree 题目连接: http://codeforces.com/contest/734/problem/E Description Anton is growing a t ...

  3. Codeforces Round #379 (Div. 2) D. Anton and Chess 水题

    D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play ...

  4. Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分

    C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...

  5. Codeforces Round #379 (Div. 2) B. Anton and Digits 水题

    B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...

  6. Codeforces Round #379 (Div. 2) A. Anton and Danik 水题

    A. Anton and Danik 题目连接: http://codeforces.com/contest/734/problem/A Description Anton likes to play ...

  7. Codeforces Round #379 (Div. 2) D. Anton and Chess 模拟

    题目链接: http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test4 secondsmem ...

  8. Codeforces Round #379 (Div. 2) E. Anton and Tree —— 缩点 + 树上最长路

    题目链接:http://codeforces.com/contest/734/problem/E E. Anton and Tree time limit per test 3 seconds mem ...

  9. Codeforces Round #379 (Div. 2) D. Anton and Chess —— 基础题

    题目链接:http://codeforces.com/contest/734/problem/D D. Anton and Chess time limit per test 4 seconds me ...

  10. Codeforces Round #379 (Div. 2) C. Anton and Making Potions —— 二分

    题目链接:http://codeforces.com/contest/734/problem/C C. Anton and Making Potions time limit per test 4 s ...

随机推荐

  1. PHP常用函数整理

    推荐网址:http://php.net/manual/zh/http://www.w3cschool.cc/php/php-ref-array.html 错误报告: error_reporting(E ...

  2. NC凭证接口(Java发送流和处理返回结果)

    问题描述: 金融行业在系统模块分为财务和业务两个系统,我公司是负责业务模块系统,NC公司负责财务系统.但是财务有时候需要生成凭证,这时候就涉及业务模块了,我方就需要写NC凭证接口.这时候就需要三方交互 ...

  3. wireshark抓包工具简介以及tcp三次握手的一些含义

    wireshark是非常流行的网络封包分析软件,功能十分强大.可以截取各种网络封包,显示网络封包的详细信息.使用wireshark的人必须了解网络协议,否则就看不懂wireshark了.为了安全考虑, ...

  4. AJAX请求时status返回状态明细表 readyState的五种状态

    在<Pragmatic Ajax A Web 2.0 Primer >中偶然看到对readyStae状态的介绍,感觉这个介绍很实在,摘译如下: 0: (Uninitialized) the ...

  5. 面向科学计算的Python IDE--Anaconda

    1.下载 2.安装,假定路径为D:/Anaconda 3.在命令行中查看已安装的包及其版本 D: cd Anaconda conda list 结果: # packages in environmen ...

  6. Java Web ——http协议响应报文

    HTTP 响应报文 HTTP 响应报文由状态行.响应头部.空行 和 响应包体 4 个部分组成,如下图所示: 下面对响应报文格式进行简单的分析: 状态行:状态行由 HTTP 协议版本字段.状态码和状态码 ...

  7. User space 与 Kernel space

    学习 Linux 时,经常可以看到两个词:User space(用户空间)和 Kernel space(内核空间). 简单说,Kernel space 是 Linux 内核的运行空间,User spa ...

  8. Linux安装ftp组件过程

    1   安装vsftpd组件 安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件. [root@bogon ~]# yum -y install vsftpd 2 ...

  9. CI加载model的问题

    1.需求 CI在linux上无法加载model 2.原因 因为linux区分大小写,且model文件名首字符要大写. As said in the comments : Your model's fi ...

  10. 整理:Javascript获取数组中的最大值和最小值的方法汇总

    方法一: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 //最小值 Array.prototype.min = function ...