Codeforces Round #379 (Div. 2)
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)的更多相关文章
- Codeforces Round #379 (Div. 2) Analyses By Team:Red & Black
A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lu ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #379 (Div. 2) B. Anton and Digits 水题
B. Anton and Digits 题目连接: http://codeforces.com/contest/734/problem/B Description Recently Anton fou ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- java关于压缩包的处理,我这里贴出三中格式的(zip,rar,tar)解压方法(目前只用到解压,所以压缩过多研究)。
1.首先我们先来说下为什么会有这三中格式: (1)rar格式:rar格式是最先出现的压缩方式,它主要是用于商业机构一些文件的压缩,它可以根据不同公司的要求,去设定制定不同的压缩算法,这种算法是不对外公 ...
- GitHub上值得关注的iOS开源项目
1.AFNetworking地址:https://github.com/AFNetworking/AFNetworking用于网络请求 2.JSONKit地址:https://github.com/j ...
- Ecmascript 6新特性
声明变量由var变成let.let实际上为JavaScript新增了块级作用域.let与var相比具有的特性有 1.不允许重复声明一个变量 var a=5; var a=7; let b=6; let ...
- flexbox学习
https://philipwalton.github.io/solved-by-flexbox/ http://www.ruanyifeng.com/blog/2015/07/flex-gramma ...
- IE7 自动为文件路径添加域名
对于图片等文件的路径,一般在同一个域名下的文件都会使用相对路径,但如果使用JS获取文件的路径浏览器获取到的路径都是相对路径,但IE7会自动为路径添加域名变成绝对路径... IE7下图片路径,在文件相对 ...
- VS2013全攻略
http://blog.csdn.net/cpp12341234/article/details/45371269 挺好的,喜欢
- Go简介
Go是Google开发的一种编译型,並發型,并具有垃圾回收功能的编程语言. 罗伯特·格瑞史莫(Robert Griesemer),罗勃·派克(Rob Pike)及肯·汤普逊于2007年9月开始设计Go ...
- WPF之命名空间和资源
1.参考: https://msdn.microsoft.com/zh-cn/library/ms747086(v=vs.110).aspx http://www.cnblogs.com/cww201 ...
- 用任务计划管理计划任务对付任务计划-禁止WPS提示升级
作为一名至今还在坚守着64位XP的XP用到死星人,因为准备升级电脑,所以准备移民外星,开始使用Windows7.其实我新电脑买来一年了,为了坚守XP,扔在一边没有装(华硕Z9PE-D8 WS主板,双E ...
- CorelDRAW x6 X8安装失败解决方法
CorelDRAW x6 X8自定义安装时,到最后经常会出现以下问题: 解决方法如下: 在自定义安装时,出现以下这个界面时,点击红色箭头的地方 将下图红色箭头指向的选项,点击取消,不要选上,即可解决安 ...