感觉最近好颓,以后不能这么颓了,要省选了,争取省选之前再板刷一面ATC???

A - Subscribers

简单容斥

#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 20000005
#define eps 1e-10
//#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 main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
int n,a,b;
read(n);read(a);read(b);
out(min(a,b));space;out(max(0,a + b - n));enter;
}

B - Touitsu

每一位单独考虑,有多少个不同的字母就改这个不同个数-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 20000005
#define eps 1e-10
//#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;
string a,b,c;
int num[4];
void Solve() {
read(N);
cin>> a >> b >> c;
int ans = 0;
for(int i = 0 ; i < N ; ++i) {
num[0] = a[i] - 'a';
num[1] = b[i] - 'a';
num[2] = c[i] - 'a';
sort(num,num + 3);
int m = unique(num,num + 3) - num - 1;
ans += m;
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

C - Different Strokes

假设第二个人全吃了,第一个人的代价就是每次\(a_{i} + b_{i}\)

第二个一口没动

#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-10
//#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;
int a[MAXN],b[MAXN],id[MAXN];
bool vis[MAXN];
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) {
read(a[i]);read(b[i]);id[i] = i;
}
sort(id + 1,id + N + 1,[](int s,int t){return a[s] + b[s] > a[t] + b[t];});
int64 ans = 0;
for(int i = 1 ; i <= N ; ++i) {
if(i & 1) ans += a[id[i]];
else ans -= b[id[i]];
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

D - Restore the Tree

每个点在拓扑图里找一条最长路,把最长路上的路径保留就是这棵树

#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-10
//#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);
}
vector<int> to[MAXN],pre[MAXN];
int N,M,deg[MAXN],p[MAXN],fa[MAXN];
queue<int> Q;
void Solve() {
read(N);read(M);
int u,v;
for(int i = 1 ; i <= N - 1 + M ; ++i) {
read(u);read(v);
deg[v]++;
to[u].pb(v);
pre[v].pb(u);
}
for(int i = 1 ; i <= N ; ++i) {
if(!deg[i]) Q.push(i);
}
while(!Q.empty()) {
int u = Q.front();Q.pop();
for(auto v : to[u]) {
p[v] = max(p[v],p[u] + 1);
if(!(--deg[v])) Q.push(v);
}
for(auto t : pre[u]) {
if(p[t] + 1 == p[u]) fa[u] = t;
}
}
for(int i = 1 ; i <= N ; ++i) {
out(fa[i]);enter;
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

E - Weights on Vertices and Edges

一个联通块合法只取决于联通块里价值最大的边

从小到大加边,判断某个价值的边在比它小的边连成的联通块里是否能达到限制

然后从大到小,每次把一条边和这个边连着的点比它小的边都连出来

如果发现一条边两个端点没联通,这条边又不合法,那这条边就得被删掉

#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-10
//#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[MAXN * 2];
int head[MAXN],sumE;
int fa[MAXN];
int64 sum[MAXN],x[MAXN];
bool vis[MAXN];
struct Enode {
int u,v,c;
}s[MAXN];
void add(int u,int v,int c) {
E[++sumE].to = v;
E[sumE].next = head[u];
E[sumE].val = c;
head[u] = sumE;
}
int getfa(int u) {
return fa[u] == u ? u : fa[u] = getfa(fa[u]);
}
void dfs(int u,int c) {
int p = getfa(u);
for(int i = head[u] ; i ; i = E[i].next) {
if(E[i].val <= c) {
int q = getfa(E[i].to);
if(q != p) {
fa[q] = p;
dfs(E[i].to,c);
}
}
}
}
void Solve() {
read(N);read(M);
for(int i = 1 ; i <= N ; ++i) read(x[i]);
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);
s[i] = (Enode){u,v,c};
}
sort(s + 1,s + M + 1,[](Enode a,Enode b){return a.c < b.c;});
for(int i = 1 ; i <= N ; ++i) {
fa[i] = i;sum[i] = x[i];
}
int t = 1;
for(int i = 1 ; i <= M ; ++i) {
int p = getfa(s[i].u),q = getfa(s[i].v);
if(p != q) {
fa[q] = p;
sum[p] += sum[q];
}
if(i == N || s[i].c != s[i + 1].c) {
for(int j = t; j <= i; ++j) {
p = getfa(s[j].u);
if(sum[p] >= s[j].c) vis[j] = 1;
}
t = i + 1;
}
}
for(int i = 1 ; i <= N ; ++i) fa[i] = i;
int ans = 0;
for(int i = M ; i >= 1 ; --i) {
if(getfa(s[i].u) == getfa(s[i].v)) continue;
if(!vis[i]) {++ans;continue;}
dfs(s[i].u,s[i].c);
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

F - Jewels

每次增加1的时候

要么就从已经选了两个点的剩余集合里+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 200005
#define eps 1e-10
//#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 pos;int64 v;
friend bool operator < (const node &a,const node &b) {
return a.v > b.v || (a.v == b.v && a.pos < b.pos);
}
};
set<node> S,D,T,CD,CS;
vector<int64> ver[MAXN];
int p[MAXN],N,K;
int64 ans,rec[MAXN];
void Choose_one() {
node t = *S.begin();S.erase(S.begin());CS.insert(t);
ans += t.v;
++p[t.pos];
if(p[t.pos] <= ver[t.pos].size() - 1) {
S.insert((node){t.pos,ver[t.pos][p[t.pos]]});
}
}
void Delete_one() {
node t = *(--CS.end());CS.erase(--CS.end());
ans -= t.v;
if(p[t.pos] <= ver[t.pos].size() - 1) {
S.erase((node){t.pos,ver[t.pos][p[t.pos]]});
}
S.insert(t);--p[t.pos];
}
void Choose_two() {
node t = *D.begin();D.erase(D.begin());CD.insert(t);
ans += t.v;
p[t.pos] = 2;
if(p[t.pos] <= ver[t.pos].size() - 1) {
S.insert((node){t.pos,ver[t.pos][p[t.pos]]});
}
if(ver[t.pos].size() >= 3) {
T.erase((node){t.pos,ver[t.pos][0] + ver[t.pos][1] + ver[t.pos][2]});
}
}
void Delete_two() {
node t = *(--CD.end());CD.erase(--CD.end());
S.erase((node){t.pos,ver[t.pos][p[t.pos]]});
D.insert((node){t.pos,ver[t.pos][0] + ver[t.pos][1]});
if(ver[t.pos].size() >= 3) {
T.insert((node){t.pos,ver[t.pos][0] + ver[t.pos][1] + ver[t.pos][2]});
}
ans -= t.v;
}
void Choose_three() {
node t = *T.begin();T.erase(T.begin());
ans += t.v;
p[t.pos] = 3;
D.erase((node){t.pos,ver[t.pos][0] + ver[t.pos][1]});
CD.insert((node){t.pos,ver[t.pos][0] + ver[t.pos][1]});
CS.insert((node){t.pos,ver[t.pos][2]});
if(p[t.pos] <= ver[t.pos].size() - 1) {
S.insert((node){t.pos,ver[t.pos][p[t.pos]]});
}
}
void Solve() {
read(N);read(K);
int c;int64 v;
for(int i = 1 ; i <= N ; ++i) {
read(c);read(v);ver[c].pb(v);
}
for(int i = 1 ; i <= K ; ++i) {
sort(ver[i].begin(),ver[i].end(),[](int64 a,int64 b){return a > b;});
}
for(int i = 1 ; i <= K ; ++i) {
if(ver[i].size()) {
D.insert((node){i,ver[i][0] + ver[i][1]});
if(ver[i].size() >= 3) T.insert((node){i,ver[i][0] + ver[i][1] + ver[i][2]});
}
}
rec[1] = -1;ans = 0;
puts("-1");
for(int i = 2 ; i <= N ; ++i) {
if(rec[i - 1] == -1) {
Choose_two();
rec[i] = ans;
}
else {
int64 w[3] = {-1,-1,-1};
if(S.size()) {
w[0] = ans + (*S.begin()).v;
}
if(CS.size() && D.size()) {
w[1] = ans - (*(--CS.end())).v + (*D.begin()).v;
}
if(CD.size() && T.size()) {
w[2] = ans - (*(--CD.end())).v + (*T.begin()).v;
}
if(w[0] < 0 && w[1] < 0 && w[2] < 0) {rec[i] = -1;}
else {
if(w[0] >= max(w[1],w[2])) {Choose_one();}
else if(w[1] >= max(w[0],w[2])) {Delete_one();Choose_two();}
else {Delete_two();Choose_three();}
rec[i] = ans;
}
while(1) {
if(!D.size()) break;
if(!CD.size()) break;
node t = *(--CD.end());
node s = *D.begin();
if(p[t.pos] == 2) {
if(s.v > t.v) {
Delete_two();Choose_two();
}
else break;
}
else break;
rec[i] = ans;
}
}
out(rec[i]);enter;
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

【AtCoder】全国統一プログラミング王決定戦予選/NIKKEI Programming Contest 2019的更多相关文章

  1. [AtCoder] NIKKEI Programming Contest 2019 (暂缺F)

    [AtCoder] NIKKEI Programming Contest 2019   本来看见这一场的排名的画风比较正常就来补一下题,但是完全没有发现后两题的AC人数远少于我补的上一份AtCoder ...

  2. AtCoder NIKKEI Programming Contest 2019 E. Weights on Vertices and Edges (并查集)

    题目链接:https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_e 题意:给出一个 n 个点 m 条边的无向图,每个点和每 ...

  3. AtCoder NIKKEI Programming Contest 2019 C. Different Strokes (贪心)

    题目链接:https://nikkei2019-qual.contest.atcoder.jp/tasks/nikkei2019_qual_C 题意:给出 n 种食物,Takahashi 吃下获得 a ...

  4. atcoder NIKKEI Programming Contest 2019 E - Weights on Vertices and Edges

    题目链接:Weights on Vertices and Edges 题目大意:有一个\(n\)个点\(m\)条边的无向图,点有点权,边有边权,问至少删去多少条边使得对于剩下的每一条边,它所在的联通块 ...

  5. [AtCoder] Yahoo Programming Contest 2019

    [AtCoder] Yahoo Programming Contest 2019   很遗憾错过了一场 AtCoder .听说这场是涨分场呢,于是特意来补一下题. A - Anti-Adjacency ...

  6. 【AtCoder】AISing Programming Contest 2019

    本来以为是1199rated的..仔细一看发现是1999,所以就做了一下 这场涨分很轻松啊...为啥又没打 等pkuwc考完我一定打一场atcoder(咕咕咕,咕咕咕,咕咕咕咕咕咕咕~) 但是其实我思 ...

  7. 【AtCoder】Yahoo Programming Contest 2019

    A - Anti-Adjacency K <= (N + 1) / 2 #include <bits/stdc++.h> #define fi first #define se se ...

  8. 【AtCoder】KEYENCE Programming Contest 2019

    A - Beginning 这个年份恐怕需要+2 #include <bits/stdc++.h> #define fi first #define se second #define p ...

  9. Atcoder Yahoo Programming Contest 2019 简要题解

    A-C 直接放代码吧. A int n,k; int main() { n=read();k=read(); puts(k<=(n+1)/2?"YES":"NO&q ...

随机推荐

  1. VS复制文件到输出目录

    1.选中项目文件 2. 3.编译时就会自动创建目录,并复制文件

  2. Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0

    1 启动hbase的时候爆出警告 Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; suppor ...

  3. 不修改加密文件名的勒索软件TeslaCrypt 4.0

    不修改加密文件名的勒索软件TeslaCrypt 4.0 安天安全研究与应急处理中心(Antiy CERT)近期发现勒索软件TeslaCrypt的最新变种TeslaCrypt 4.0,它具有多种特性,例 ...

  4. SpringBoot2.x整合Redis实战 4节课

    1.分布式缓存Redis介绍      简介:讲解为什么要用缓存和介绍什么是Redis,新手练习工具 1.redis官网 https://redis.io/download          2.新手 ...

  5. 【转】shell编程下 特殊变量、test / [ ]判断、循环、脚本排错

    [转]shell编程下 特殊变量.test / [ ]判断.循环.脚本排错 第1章 shell中的特殊变量 1.1 $# $# 表示参数的个数 1.1.1 [示例]脚本内容 [root@znix ~] ...

  6. git获取内核源码的方法

    [转]http://www.360doc.com/content/17/0410/16/23107068_644444795.shtml 1. 前言 本文主要讲述ubuntu下通过git下载linux ...

  7. 转载:(Mac)在bash和zsh配置环境变量path的几种方法

    参考文献 老习惯,列出本文参考或引用或转载的文档和博客,致以崇高的敬意,感兴趣的可以去看看 1.http://postgresapp.com/ 2.http://postgresapp.com/doc ...

  8. 字符串cookies转字典 scrapy使用。

    配置文件 DOWNLOADER_MIDDLEWARES = { 'weibo.middlewares.CookiesMiddleware': 543, } 中间件内容 class CookiesMid ...

  9. dubbo系列五、dubbo核心配置

    一.配置文件 1.生产者配置provider.xml <?xml version="1.0" encoding="UTF-8"?> <bean ...

  10. js 将图片连接转换称base64格式

    我们把图像文件的内容直接写在了HTML 文件中,这样做的好处是,节省了一个HTTP 请求.坏处呢,就是浏览器不会缓存这种图像.现在我们提供一个js: function convertImgToBase ...