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

上一篇:亲测可行,AndroidStudio 究竟如何配置gradle


下一篇:使用SoapUI工具做get请求和post请求接口测试