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. navicat for mysql 破解版

    Navicat for MySQL下载地址:Navicat for MySQL 软件和破解程序 第1步.安装Navicat软件,最后点击完成 第2步.安装成功之后还要进行破解.点击patchNavic ...

  2. dbms_job和dbms_job基础学习

    一.dbms_job学习 a.创建job: dbms_job.submit(jobno,what,next_date,interval);b.删除job: dbms_job.remove(jobno) ...

  3. C语言指针的大小

    C语言指针的大小 今天看到一道题目是这样的,写出以下变量在32位设备上的大小(占多少个字节) 然后其中就有一些指针类型的数据,那么我们知道在C语言中指针的大小都是一样的,不管是有数据类型的还是void ...

  4. LeetCode94 二叉树的中序遍历

    给定一个二叉树,返回它的中序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3 输出: [1,3,2] 进阶: 递归算法很简单,你可以通过迭代算法完成吗?       /** * ...

  5. 【C++】《Effective C++》第八章

    第八章 定制new和delete 对于程序开发来说,了解C++内存管理例程的行为是非常重要的.其中两个主角是分配例程和归还例程(operator new和operator delete),配角是new ...

  6. 【Flutter】容器类组件之装饰容器

    前言 DecoratedBox可以在其子组件绘制前后绘制一些装饰,例如背景,边框,渐变等. 接口描述 const DecoratedBox({ Key key, // 代表要绘制的装饰 @requir ...

  7. LeetCode637. 二叉树的层平均值

    题目 1 class Solution { 2 public: 3 vector<double>ans; 4 vector<double> averageOfLevels(Tr ...

  8. LeetCode108.有序数组转二叉搜索树

    题目 1 class Solution { 2 public: 3 TreeNode* sortedArrayToBST(vector<int>& nums) { 4 if(num ...

  9. 利用sql_tuning_Advisor调优sql

    1.赋权给调优用户 grant ADVISOR to xxxxxx; 2.创建调优任务 使用sql_text创建 DECLARE my_task_name VARCHAR2 (30); my_sqlt ...

  10. Java中的深浅拷贝问题,你清楚吗?

    一.前言 拷贝这个词想必大家都很熟悉,在工作中经常需要拷贝一份文件作为副本.拷贝的好处也很明显,相较于新建来说,可以节省很大的工作量.在Java中,同样存在拷贝这个概念,拷贝的意义也是可以节省创建对象 ...