C - Splitting Pile

枚举从哪里开始分的即可

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
int64 s[MAXN];
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) read(s[i]);
for(int i = 1 ; i <= N ; ++i) s[i] += s[i - 1];
int64 ans = abs(s[N] - 2 * s[1]);
for(int i = 1 ; i < N ; ++i) {
ans = min(ans,abs(s[N] - 2 * s[i]));
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

D - Fennec VS. Snuke

看树上这段链从Fennec开始数第K / 2和K / 2+1的边断开之后,分成的两个子树哪个结点多

Fennec只有当节点数大于Snuke才会胜利

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
struct node {
int to,next;
}E[MAXN * 2];
int head[MAXN],sumE,N;
int dep[MAXN],fa[MAXN],siz[MAXN];
void add(int u,int v) {
E[++sumE].to = v;
E[sumE].next = head[u];
head[u] = sumE;
}
void dfs(int u) {
dep[u] = dep[fa[u]] + 1;
siz[u] = 1;
for(int i = head[u] ; i ; i = E[i].next) {
int v = E[i].to;
if(v != fa[u]) {
fa[v] = u; dfs(v);
siz[u] += siz[v];
}
}
}
void Solve() {
read(N);
int u,v;
for(int i = 1 ; i < N ; ++i) {
read(u);read(v);
add(u,v);add(v,u);
}
dfs(1);
int t = dep[N] / 2 - 1;
u = N;
while(t--) {u = fa[u];}
if(N - siz[u] > siz[u]) puts("Fennec");
else puts("Snuke");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

E - Awkward Response

如果不为1后面接的只有0的形式,那么问出第一个\(10^k\)为N则证明数字有k位,然后可以通过二分,判断中间值是否小于当前值可以把mid扩大10倍,这样可以知道中间值的字典序是否大于还是小于n,因为长度相等字典序顺序就是大小顺序,所以可行

如果是1后面接的只有0,那么问出第一个合法的k个9,这个数就是\(10^{k - 1}\)

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
bool Query(int64 t) {
putchar('?');space;out(t);enter;fflush(stdout);
char s[5];scanf("%s",s);
return s[0] == 'Y';
}
void Solve() {
int64 v = 1;
bool f = 0;
for(int i = 1 ; i <= 10 ; ++i) {
if(!Query(v)) {f = 1;v /= 10;break;}
v *= 10;
}
if(!f) {
v = 1;
for(int i = 1 ; i <= 10 ; ++i) {
if(Query(v * 10 - 1)) {putchar('!');space;out(v);enter;return;}
v *= 10;
}
}
int64 L = v,R = min(v * 10 - 1,(int64)1e9);
while(L < R) {
int64 mid = (L + R + 1) >> 1;
if(!Query(mid * 10)) L = mid;
else R = mid - 1;
}
putchar('!');space;out(L + 1);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

F - Mole and Abandoned Mine

为啥算完2s跑出来不到0.1s???

atc扩充我的想象力系列???

这个就是把这唯一一条路径挑出来,肯定是希望这条路径和路径上每个点上挂的一个联通块价值最大,然后用总路径价值减掉

然后dp[i][S]表示当前走到第i个点,已经扩充的点集是S,就是每次路径往下走一个点,或者扩充一个包括i其余的点不在S中的点集即可,复杂度\(O(N\times 3^{N})\)

然后我过于智障写错了好几遍,cao

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 10005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,M;
struct node {
int to,next,val;
}E[1005];
int sumE,head[25],pos[(1 << 15) + 5];
int f[16][(1 << 15) + 5],h[16][(1 << 15) + 5],sum[(1 << 15) + 5];
void add(int u,int v,int c) {
E[++sumE].to = v;
E[sumE].next = head[u];
E[sumE].val = c;
head[u] = sumE;
}
inline int lowbit(int x) {
return x & (-x);
}
void Init() {
read(N);read(M);
int u,v,c;
for(int i = 1 ; i <= M ; ++i) {
read(u);read(v);read(c);
add(u,v,c);add(v,u,c);
h[u][1 << v - 1] = c;
h[v][1 << u - 1] = c;
}
for(int i = 1 ; i <= N ; ++i) {
for(int j = 1 ; j < (1 << N) ; ++j) {
if(lowbit(j) == j) continue;
h[i][j] = h[i][j - lowbit(j)] + h[i][lowbit(j)];
}
}
for(int i = 1 ; i <= N ; ++i) pos[(1 << i - 1)] = i;
for(int i = 1 ; i < (1 << N) ; ++i) {
sum[i] = sum[i - lowbit(i)] + h[pos[lowbit(i)]][i - lowbit(i)];
}
}
void Solve() {
for(int i = 1 ; i <= N ; ++i) {
for(int j = 0 ; j < (1 << N) ; ++j) {
f[i][j] = -1e9;
}
}
f[1][1] = 0; for(int j = 0 ; j < (1 << N - 1) ; ++j) {
for(int i = 1 ; i <= N ; ++i) {
int S = j << 1 | 1;
if(!(S & (1 << i - 1))) continue;
int L = S ^ (1 << i - 1);
for(int T = L; T ; T = (T - 1) & L) {
if(f[i][S ^ T] >= 0)
f[i][S] = max(f[i][S],f[i][S ^ T] + sum[T ^ (1 << i - 1)]);
}
if(f[i][S] >= 0) {
for(int k = head[i] ; k ; k = E[k].next) {
int v = E[k].to;
if(!(S & (1 << v - 1))) {
f[v][S ^ (1 << v - 1)] = max(f[v][S ^ (1 << v - 1)],f[i][S] + E[k].val);
}
}
}
}
}
out(sum[(1 << N) - 1] - f[N][(1 << N) - 1]);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Init();
Solve();
}

【AtCoder】ARC078的更多相关文章

  1. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  2. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  3. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  4. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

  5. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  6. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

  7. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  8. 【Atcoder】AGC022 C - Remainder Game 搜索

    [题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...

  9. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

随机推荐

  1. Ubuntu14.10安装TensorFlow1.0.1

    本文记录了在Ubuntu上安装TensorFlow的步骤.系统环境:Ubuntu14.10 64bitPython版本:Python 2.7.8TensorFlow版:TensorFlow 1.0.1 ...

  2. 让富文本编辑器支持复制doc中多张图片直接粘贴上传

    Chrome+IE默认支持粘贴剪切板中的图片,但是我要发布的文章存在word里面,图片多达数十张,我总不能一张一张复制吧? 我希望打开文档doc直接复制粘贴到富文本编辑器,直接发布 感觉这个似乎很困难 ...

  3. spring boot(十一):Spring boot中mongodb的使用

    mongodb简介 传统的关系数据库一般由数据库(database).表(table).记录(record)三个层次概念组成, MongoDB是由数据库(database).集合(collection ...

  4. Mask RCNN 简单使用

    涉及到的知识点补充: FasterRCNN:https://www.cnblogs.com/wangyong/p/8513563.html RoIPooling.RoIAlign:https://ww ...

  5. dbms_metadata.get_ddl的用法(DDL)

    dbms_metadata包中的get_ddl函数 --GET_DDL: Return the metadata for a single object as DDL. -- This interfa ...

  6. ubuntu 14.04 软件中心闪退解决方案

    法一: gksudo gedit /usr/share/software-center/softwarecenter/ui/gtk3/views/lobbyview.py 注释下面这句话(注释使用#号 ...

  7. SpringBoot几个重要的事件回调、监听机制

    (1).需要配置在META-INF/Spring.factories 1.ApplicationContextInitializer // // Source code recreated from ...

  8. Difference between plt.draw() and plt.show() in matplotlib

    Difference between plt.draw() and plt.show() in matplotlib down voteaccepted plt.show() will display ...

  9. 《Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks》

    <Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks> 论文主要的三个贡 ...

  10. CentOS配置SSH无密码

    210-211/212/213的集群中,新增215节点,操作:1.将210的id_rsa.pub拷贝到215中:scp ~/.ssh/id_rsa.pub 192.168.0.215@host:/ho ...