Educational Codeforces Round 43 

A. Minimum Binary Number

显然可以把所有\(1\)合并成一个

注意没有\(1\)的情况

view code
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}; void solve(){
int n;
string s;
cin >> n >> s;
int c0 = 0, c1 = 0;
for(int x : s) if(x=='0') c0++; else c1++;
if(!c1) cout << 0 << endl;
else{
cout << 1;
while(c0--) cout << 0;
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("Local.in","r",stdin);
freopen("ans.out","w",stdout);
#endif
solve();
return 0;
}

B. Lara Croft and the New Game

就摁模拟它怎么走的就好了,有点小麻烦

view code
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
typedef long long int LL;
void solve(){
LL n, m, k;
cin >> n >> m >> k;
if(k<n) cout << k + 1 << ' ' << 1 << endl;
else{
k -= n;
int num = k / (m-2+m);
int lft = k % (m-2+m);
int x = n - 2 * num;
if(!lft) cout << x << ' ' << 2 << endl;
else{
if(lft<=m-2) cout << x << ' ' << 2 + lft << endl;
else{
lft -= m - 1;
x -= 1;
cout << x << ' ' << m - lft << endl;
}
}
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("Local.in","r",stdin);
freopen("ans.out","w",stdout);
#endif
solve();
return 0;
}

C. Nested Segments

把所有线段先按左端点从小到大排序,左端点相同的按右端点从大到小排,然后扫一遍,这样就不用管左端点的大小关系了,只要维护遍历过程中右端点最右的位置和相应线段的编号即可

view code
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 3e5+7; int n;
pair<pair<int,int>,int> seg[MAXN];
void solve(){
____();
cin >> n;
for(int i = 1; i <= n; i++){
cin >> seg[i].first.first >> seg[i].first.second;
seg[i].second = i;
}
sort(seg+1,seg+1+n,[&](pair<pair<int,int>, int> a, pair<pair<int,int>,int > b){
if(a.first.first==b.first.first) return a.first.second > b.first.second;
else return a.first.first < b.first.first;
});
int rm = 0, id = 0;
for(int i = 1; i <= n; i++){
if(seg[i].first.second>rm){
rm = seg[i].first.second;
id = seg[i].second;
}else{
cout << seg[i].second << ' ' << id << endl;
return;
}
}
cout << -1 << ' ' << -1 << endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("Local.in","r",stdin);
freopen("ans.out","w",stdout);
#endif
solve();
return 0;
}

D. Degree Set

一开始有\(d_n+1\)个点,要构造出度数集合为\(d_1,d_2,\cdots,d_n\)的图

把编号\(1-d_1\)的点向其他所有点连边,那么\(1-d_1\)的点的度数为\(d_n-1\),其他点的度数为\(d_1\)

保留\(1-d_1\)的点和\(d_{n-1}+2-d_n+1\)的点

剩下的\(d_1+1-d_{n-1}+1\)的点(一共\(d_{n-1}-d_1+1\)个点),需要构造一个度数集合为\(d_2-d_1,d_3-d_1,\cdots,d_{n-1}-d_1\)的图,可以发现是一个小规模的原问题,递归解决即可

view code
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1e3+7; void solve(){
____();
static int n, d[MAXN]; cin >> n;
for(int i = 1; i <= n; i++) cin >> d[i];
vector<pair<int,int> > edges;
int l = 1, r = n, D = 0;
for(int l = 1, r = n, D = 0; l <= r; D += d[l], l++, r--){
for(int i = 1; i <= d[l]; i++) for(int j = i + 1; j <= d[r] + 1; j++) edges.push_back({i+D,j+D});
for(int i = l + 1; i <= r - 1; i++) d[i] -= d[l];
}
printf("%d\n",edges.size());
for(auto &e : edges) printf("%d %d\n",e.first,e.second);
}
int main(){
#ifndef ONLINE_JUDGE
freopen("Local.in","r",stdin);
freopen("ans.out","w",stdout);
#endif
solve();
return 0;
}

E. Well played!

显然把生命翻倍给同一个随从是最优的

那么枚举给的这个随从即可

注意没有心火(攻击等于生命)的情况

view code
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
typedef long long int LL;
const int MAXN = 2e5+7; int n, a, b;
pair<LL,LL> cre[MAXN];
LL pre[MAXN];
void solve(){
____();
cin >> n >> a >> b;
b = min(n,b);
for(int i = 1; i <= n; i++) cin >> cre[i].first >> cre[i].second;
sort(cre+1,cre+1+n,[&](pair<LL,LL> &a, pair<LL,LL> &b){
return a.first - a.second > b.first - b.second;
});
for(int i = 1; i <= n; i++) pre[i] = pre[i-1] + max(0ll,cre[i].first - cre[i].second);
LL sum = 0, ret = 0;
for(int i = 1; i <= n; i++) sum += cre[i].second;
ret = sum + pre[b];
sum += pre[b];
for(int i = 1; i <= b; i++){
LL ts = sum - max(0ll,cre[i].first-cre[i].second);
ts -= cre[i].second;
ret = max(ret,ts+(cre[i].first<<a));
}
if(b){
for(int i = b + 1; i <= n; i++){
LL ts = sum - max(0ll,cre[b].first-cre[b].second);
ts -= cre[i].second;
ret = max(ret,ts+(cre[i].first<<a));
}
}
cout << ret << endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("Local.in","r",stdin);
freopen("ans.out","w",stdout);
#endif
solve();
return 0;
}

F. Minimal k-covering

考虑网络流建图,所有边从左半图连右半图,容量为\(1\),源点向左半图所有点连边,容量为\(deg[x]-k\),右半图的点向汇点连边,容量为\(deg[y]-k\),然后有流量的边边即为需要删掉的边

从大到小枚举\(k\),每次从源点到左半图的点增加\(1\)容量的边,右半图的点向汇点增加\(1\)容量的边,增广一次即可

view code
//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 4e3+7;
const int INF = 0x3f3f3f3f;
#define S 0
#define T MAXN - 1
set<int> edges;
struct EDGE{
int to,cap,rev,id;
EDGE(){};
EDGE(int to, int cap, int rev, int id):to(to),cap(cap),rev(rev),id(id){};
};
vector<EDGE> G[MAXN];
int iter[MAXN],rk[MAXN];
void ADDEDGE(int u, int v, int cap, int id){
G[u].push_back(EDGE(v,cap,(int)G[v].size(),id));
G[v].push_back(EDGE(u,0,(int)G[u].size()-1,-id));
}
bool bfs(){
memset(rk,0,sizeof(rk));
memset(iter,0,sizeof(iter));
rk[S] = 1;
queue<int> que;
que.push(S);
while(!que.empty()){
int u = que.front();
que.pop();
for(auto e : G[u]){
if(!e.cap or rk[e.to]) continue;
rk[e.to] = rk[u] + 1;
que.push(e.to);
}
}
return rk[T]!=0;
}
int dfs(int u, int flow){
if(u==T) return flow;
for(int &i = iter[u]; i < (int)G[u].size(); i++){
auto &e = G[u][i];
if(!e.cap or rk[e.to]!=rk[u]+1) continue;
int d = dfs(e.to,min(e.cap,flow));
if(d){
e.cap -= d;
G[e.to][e.rev].cap += d;
if(e.id){
if(e.id>0) edges.erase(e.id);
else edges.insert(-e.id);
}
return d;
}
}
return 0;
}
void Dinic(){
while(bfs()){
int d = dfs(S,INF);
while(d) d = dfs(S,INF);
}
}
int n1, n2, m, deg1[MAXN], deg2[MAXN];
void solve(){
____();
cin >> n1 >> n2 >> m;
for(int i = 1; i <= m; i++){
int u, v; cin >> u >> v;
ADDEDGE(u,v+n1,1,i);
deg1[u]++; deg2[v]++;
}
for(int i = 1; i <= m; i++) edges.insert(i);
int mindeg = min(*min_element(deg1+1,deg1+1+n1),*min_element(deg2+1,deg2+1+n2));
vector<vector<int> > vec(mindeg,vector<int>());
for(int i = 1; i <= n1; i++) ADDEDGE(S,i,deg1[i]-mindeg,0);
for(int i = 1; i <= n2; i++) ADDEDGE(i+n1,T,deg2[i]-mindeg,0);
for(int k = mindeg; k; k--){
Dinic();
for(int e : edges) vec[k-1].push_back(e);
for(int i = 1; i <= n1; i++) ADDEDGE(S,i,1,0);
for(int i = 1; i <= n2; i++) ADDEDGE(i+n1,T,1,0);
}
puts("0");
for(int i = 0; i < mindeg; i++){
printf("%d",vec[i].size());
for(int x : vec[i]) printf(" %d",x);
puts("");
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("Local.in","r",stdin);
freopen("ans.out","w",stdout);
#endif
solve();
return 0;
}

Educational Codeforces Round 43的更多相关文章

  1. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  2. Educational Codeforces Round 43 E&976E. Well played! 贪心

    传送门:http://codeforces.com/contest/976/problem/E 参考:https://www.cnblogs.com/void-f/p/8978658.html 题意: ...

  3. Educational Codeforces Round 43 (Rated for Div. 2) ABCDE

    A. Minimum Binary Number time limit per test 1 second memory limit per test 256 megabytes input stan ...

  4. Educational Codeforces Round 43 E. Well played!(贪心)

    E. Well played! time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  5. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  6. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  7. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  8. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  9. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

随机推荐

  1. nginx 重写去掉index.php

    if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?s=$1 last; }

  2. C++ 简单输出当前日期时间

    根据https://www.runoob.com/cplusplus/cpp-date-time.html编写. 首先介绍2个数据类型. 一个是time_t,与时间函数相关的变量,定义的变量记录着自 ...

  3. Java高并发与多线程(二)-----线程的实现方式

    今天,我们开始Java高并发与多线程的第二篇,线程的实现方式. 通常来讲,线程有三种基础实现方式,一种是继承Thread类,一种是实现Runnable接口,还有一种是实现Callable接口,当然,如 ...

  4. 透过现象看本质:Java类动态加载和热替换

    摘要:本文主要介绍类加载器.自定义类加载器及类的加载和卸载等内容,并举例介绍了Java类的热替换. 最近,遇到了两个和Java类的加载和卸载相关的问题: 1) 是一道关于Java的判断题:一个类被首次 ...

  5. oracle编译表上失效USERDBY脚本

    对表进行DLL操作之后,依赖这个表的一些存储过程,触发器等会失效,可以用下边的脚本进行重编译 /* Formatted on 2020/7/8 上午 09:31:31 (QP5 v5.163.1008 ...

  6. 入门OJ:photo

    题目描述 有N个人,来自K个家族.他们排成一行准备照相,但是由于天生的排外性,每个人都希望和本家族的人站在一起,中间不要加入别的家族的人.问最少从队列中去掉多少个就可以达到这个目的. 输入格式 第一行 ...

  7. 【Azure App Service For Container】创建ASP.NET Core Blazor项目并打包为Linux镜像发布到Azure应用服务

    欢迎使用 Blazor!Blazor 是一个使用 .NET 生成交互式客户端 Web UI 的框架: 使用 C# 代替 JavaScript 来创建信息丰富的交互式 UI. 共享使用 .NET 编写的 ...

  8. 30分钟带你了解「消息中间件」Kafka、RocketMQ

    消息中间件的应用场景 主流 MQ 框架及对比 说明 Kafka 优点 Kafka 缺点 RocketMQ Pulsar 发展趋势 各公司发展 Kafka Kafka 是什么? Kafka 术语 Kaf ...

  9. 遍历仓库里的 commit log 替换author

    #!/bin/sh # 遍历仓库里的 commit log, 替换author git filter-branch --env-filter ' an="$GIT_AUTHOR_NAME&q ...

  10. 关于Java客户端连接虚拟机中的Kafka时,无法发送、接收消息的问题

    kafka通过控制台模拟消息发送和消息接收正常,但是通过javaAPI操作生产者发送消息不成功 消费者接收不到数据解决方案? 1.问题排查 (1)首先通过在服务器上使用命令行来模拟生产.消费数据,发现 ...