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 ...
随机推荐
- Linux 命令
Linux 常用命令 su root 切换root用户 touch /etc/www/html/1.txt 创建文件 mkdir /usr/local/apache2 建立文件夹 rm -rf ...
- mysql myisam简单分表设计
一般来说,当我们的数据库的数据超过了100w记录的时候就应该考虑分表或者分区了,这次我来详细说说分表的一些方法.目前我所知道的方法都是MYISAM的,INNODB如何做分表并且保留事务和外键,我还不是 ...
- Digester组件
刚认识Digester,记录一下: Digester随着Struts的发展以及其的公用性而被提到commons中独自立项,是apache的一个组件 apache commons-digester.ja ...
- 使用powershell批量添加Qt的文件(生成pro)
想使用QtCreator作为编辑器编辑keil或者IAR的工程,需要生成.pro文件,于是使用powershell批量处理. 源码如下: $incPath = dir -filter "*. ...
- runtime-给系统已有类添加属性
在没有接触runtime之前,我们接触到的能给类进行扩展的方法有类目(category)和延展(extension)两种.类目(category)可以给系统已有类添加扩展方法但是不能添加属性,并且被添 ...
- codility flags solution
How to solve this HARD issue 1. Problem: A non-empty zero-indexed array A consisting of N integers i ...
- SQL查询某个时间段共多少条数据
select COUNT(*) from (表名) where (时间字段)between '2012-05-01 00:00:00' and '2012-05-31 23:59:59' 获取ASP. ...
- CentOs 6.5 安装Ganglia步骤
一 . 说明 Ganglia由gmond.gmetad和gweb三部分组成 gmond(Ganglia Monitoring Daemon)是一种轻量级服务,安装在每台需要收集指标数据的节点主机上.g ...
- MFC像窗体坐标位置发送 点击消息
int x11=495; int y22=600; ...
- JavaScript对象创建,继承
创建对象 在JS中创建对象有很多方式,第一种: var obj = new Object(); 第二种方式: var obj1 = {};//对象直面量 第三种方式:工厂模式 function Per ...