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 ...
随机推荐
- 3种方法修改PHP时区
PHP5.2.4之前的版本无需设置时区.下面是修改PHP时区的三个办法. 1.修改PHP.ini这个文件 找到date.timezone这行,去掉前面的分号,改成: date.timezone = A ...
- 如何解决inline和linline-block在浏览器中的间距问题
写页面时,如果想要元素从左到右排列,但又不想使用浮动,那么很多人都会用到display:inline或者display:inline-block. 但是每次一用到这个两个属性,浏览器中浏览的时候就会有 ...
- 耗时两月,NHibernate系列出炉
写在前面 这篇总结本来是昨天要写的,可昨天大学班长来视察工作,多喝了点,回来就倒头就睡了,也就把这篇总结的文章拖到了今天. nhibernate系列从开始着手写,到现在前后耗费大概两个月的时间,通过总 ...
- 一个简单实用的css loading图标
摘要 在web开发中,为了提高用户体验,在加载数据的时候都会给一个loading的提示. Html <!DOCTYPE html> <html xmlns="http:// ...
- easyui如何动态改变列的编辑属性
动态改变列的编辑属性 var tt=$('#dg').datagrid('getColumnOption', 'yearContent'); //通过列名获得此列 tt.editor={type:'t ...
- CSS解决未知高度垂直居中
尽管有CSS的vertical-align特性,但是并不能有效解决未知高度的垂直居中问题(在一个DIV标签里有未知高度的文本或图片的情况下). 标准浏览器如Mozilla, Opera, Safari ...
- google觉得好用的插件(不断更新)
1.Octotree 访问github可以显示工程结构. 2.vysor 免费版可以让手机在电脑演示,其中付费版还可以电脑操作手机.
- Yii2 ActiveRecord save失败
当给AR写beforeSave方法时,注意返回true还是false.如果没有返回值,或者返回false,那么就不会存入数据库.如下 晚上写代码的时候beforeSave忘了返回true,导致无法存入 ...
- PHP延迟静态绑定
类可以自下往上调用父类方法,如果需要在父类中根据不同的子类,来调用子类的方法,那么就需要延迟静态绑定.延迟静态绑定用的是保留关键词static. 所谓延迟静态绑定,顾名思义,静态调用时::符号左侧的部 ...
- sublime自动生成头部注释
1.在tool->new snippet-创建一个新的snippet sublime text2 用snippet 创建文件头部信息 Snippets are smart templates t ...