Educational Codeforces Round 43
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的更多相关文章
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 43 E&976E. Well played! 贪心
传送门:http://codeforces.com/contest/976/problem/E 参考:https://www.cnblogs.com/void-f/p/8978658.html 题意: ...
- 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 ...
- 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 ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [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 ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
随机推荐
- HarmonyOS三方件开发指南(4)——Logger组件
目录: 1. Logger功能介绍 2. Logger使用方法 3. Logger开发实现 4. 源码上传地址 1. Logger功能介绍1.1. ...
- LeetCode144 二叉树的前序遍历
给定一个二叉树,返回它的 前序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,2,3] 进阶: 递归算法很简单,你可以通过迭代算法完成吗? /** * Defin ...
- 深入理解nodejs中的异步编程
目录 简介 同步异步和阻塞非阻塞 javascript中的回调 回调函数的错误处理 回调地狱 ES6中的Promise 什么是Promise Promise的特点 Promise的优点 Promise ...
- 【设计模式】Java设计模式精讲之原型模式
简单记录 - 慕课网 Java设计模式精讲 Debug方式+内存分析 & 设计模式之禅-秦小波 文章目录 1.原型模式的定义 原型-定义 原型-类型 2.原型模式的实现 原型模式的通用类图 原 ...
- 【Spring】XML方式实现(无参构造 有参构造)和注解方式实现 IoC
文章目录 Spring IoC的实现方式 XML方式实现 通过无参构造方法来创建 1.编写一个User实体类 2.编写我们的spring文件 3.测试类 UserTest.java 4.测试结果 通过 ...
- 【Mysql】[Err] 1153 - Got a packet bigger than 'max_allowed_packet' bytes
今天用Navicat导入的时候报错 [Err] 1153 - Got a packet bigger than 'max_allowed_packet' bytes 原因是数据库默认是16M的数据,这 ...
- freopen函数总结
函数原型: freopen(const char * __restrict__ _Filename,const char * __restrict__ _Mode,FILE * __restrict_ ...
- mysql—group_concat函数
MySQL中的group_concat函数的使用方法,比如select group_concat(name) . 完整的语法如下: group_concat([DISTINCT] 要连接的字段 [Or ...
- oracle rac搭建单实例DG步骤(阅读全篇后再做)
环境介绍 主库: 主机名 rac01 rac02 实体IP 10.206.132.232 10.206.132.233 私有IP 192.168.56.12 192.168.56.13 虚拟IP 10 ...
- Linux操作系统相关资料
玩转Linux操作系统 操作系统发展史 只有硬件没有软件的计算机系统被称之为"裸机",我们很难用"裸机"来完成计算机日常的工作(如存储和运算),所以必须用特定的 ...