Educational Codeforces Round 43 (Rated for Div. 2) ABCDE
1 second
256 megabytes
standard input
standard output
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string s.
You can perform two different operations on this string:
- swap any pair of adjacent characters (for example, "101"
"110");
- replace "11" with "1" (for example, "110"
"10").
Let val(s) be such a number that s is its binary representation.
Correct string a is less than some other correct string b iff val(a) < val(b).
Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).
The first line contains integer number n (1 ≤ n ≤ 100) — the length of string s.
The second line contains the string s consisting of characters "0" and "1". It is guaranteed that the string s is correct.
Print one string — the minimum correct string that you can obtain from the given one.
4
1001
100
1
1
1
In the first example you can obtain the answer by the following sequence of operations: "1001" "1010"
"1100"
"100".
In the second example you can't obtain smaller answer no matter what operations you use.
题意:对一一个数的二进制表示可以进行两个操作:交换相邻两个二进制位以及合并两个1为一个1,问通过这两个操作能得到的不含前导0的最小数字是多少。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007
#define clr_1(x) memset(x,-1,sizeof(x))
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
using namespace std;
const int N=1e5+;
char s[N];
int n,m,zero,one;
int main()
{
scanf("%d",&n);
scanf("%s",s);
for(int i=;s[i];i++)
{
if(s[i]=='')
zero++;
else
one++;
}
if(n== && zero==)
{
printf("0\n");
return ;
}
else
{
printf("");
while(zero)
{
printf("");
zero--;
}
printf("\n");
}
return ;
}
2 seconds
256 megabytes
standard input
standard output
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.
Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. nand m given are such that she always end up in cell (1, 2).
Lara has already moved to a neighbouring cell k times. Can you determine her current position?
The only line contains three integers n, m and k (2 ≤ n, m ≤ 109, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!
Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.
4 3 0
1 1
4 3 11
1 2
4 3 7
3 2
题意:有一个人在n*m的方格里走,每次只能走通往上下左右的一步。不过他有既定路线:先从(1,1)到(n,1),然后蛇形地走,每次从(k,2)走(k,m)然后到(k-1,m)接着到(k-1,2)然后到(k-2,2)这样不断循环。然后问你他走第k步的时候在哪里。
题解:先处理(1,1)到(1,n)的情况,然后通过取模整除处理余下情况。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007
#define clr_1(x) memset(x,-1,sizeof(x))
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
using namespace std;
const int N=1e5+;
LL n,m,k,s,row,col,t;
int main()
{
scanf("%I64d%I64d%I64d",&n,&m,&k);
if(k<n)
{
printf("%I64d 1\n",k+);
return ;
}
k-=n-;
m--;
s=k%m;
t=k/m;
if(s==)
{
row=n-t+;
col=(t&)?m+:;
}
else
{
row=n-t;
col=(t&)?m+-s:+s;
}
printf("%I64d %I64d\n",row,col);
return ;
}
2 seconds
256 megabytes
standard input
standard output
You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices iand j such that segment ai lies within segment aj.
Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2.
Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
The first line contains one integer n (1 ≤ n ≤ 3·105) — the number of segments.
Each of the next n lines contains two integers li and ri (1 ≤ li ≤ ri ≤ 109) — the i-th segment.
Print two distinct indices i and j such that segment ai lies within segment aj. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
5
1 10
2 9
3 9
2 3
2 9
2 1
3
1 5
2 6
6 20
-1 -1
题意:给你一堆一维的线段的左右端点,让你找出一条线段完全被包含在另一条线段的情况,并输出这两条线段编号。若没有输出-1 -1。
题解:经典黑书线段覆盖题,按左端点为第一关键字从小到大,右端点为第二关键字从大到小排序就好了。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007
#define clr_1(x) memset(x,-1,sizeof(x))
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
using namespace std;
const int N=3e5+;
struct sem
{
int l,r,id;
}seg[N];
bool cmp(sem a,sem b)
{
if(a.l==b.l) return a.r>b.r;
return a.l<b.l;
}
int u,v,n,maxr,id;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&seg[i].l,&seg[i].r);
seg[i].id=i;
}
sort(seg+,seg+n+,cmp);
for(int i=;i<=n;i++)
{
if(seg[i].l==seg[i-].l)
{
printf("%d %d\n",seg[i].id,seg[i-].id);
return ;
}
else if(seg[i].r<=seg[i-].r)
{
printf("%d %d\n",seg[i].id,seg[i-].id);
return ;
}
}
printf("-1 -1\n");
return ;
}
2 seconds
256 megabytes
standard input
standard output
You are given a sequence of n positive integers d1, d2, ..., dn (d1 < d2 < ... < dn). Your task is to construct an undirected graph such that:
- there are exactly dn + 1 vertices;
- there are no self-loops;
- there are no multiple edges;
- there are no more than 106 edges;
- its degree set is equal to d.
Vertices should be numbered 1 through (dn + 1).
Degree sequence is an array a with length equal to the number of vertices in a graph such that ai is the number of vertices adjacent toi-th vertex.
Degree set is a sorted in increasing order sequence of all distinct values from the degree sequence.
It is guaranteed that there exists such a graph that all the conditions hold, and it contains no more than 106 edges.
Print the resulting graph.
The first line contains one integer n (1 ≤ n ≤ 300) — the size of the degree set.
The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 1000, d1 < d2 < ... < dn) — the degree set.
In the first line print one integer m (1 ≤ m ≤ 106) — the number of edges in the resulting graph. It is guaranteed that there exists such a graph that all the conditions hold and it contains no more than 106 edges.
Each of the next m lines should contain two integers vi and ui (1 ≤ vi, ui ≤ dn + 1) — the description of the i-th edge.
3
2 3 4
8
3 1
4 2
4 5
2 5
5 1
3 2
2 1
5 3
3
1 2 3
4
1 2
1 3
1 4
2 3
题意:给出无向图所有节点的度组成的集合(集合默认从大到小并且不重复),且无向图中无重边自环,节点数为最高度+1。询问一种构造方式能构造出一个符合上述度集以及要求的图,输出所有的边。保证一定有这样的图存在。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007
#define clr_1(x) memset(x,-1,sizeof(x))
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
using namespace std;
const int N=3e3+;
int a[N];
vector<int> dt[N];
int rt,n,p,lt,r,l,ans;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",a+i);
for(int i=;i<=a[n]+;i++)
dt[i].clear();
rt=n;
r=a[n]+;
lt=;
l=;
while(lt<=rt)
{
while(dt[l].size()<a[lt])
{
for(int j=l;j<r;j++)
dt[j].pb(r);
r--;
}
rt--;
lt++;
l=a[n]+-a[rt];
}
ans=;
for(int i=;i<=a[n]+;i++)
ans+=dt[i].size();
printf("%d\n",ans);
for(int u=;u<=a[n]+;u++)
{
for(auto v:dt[u])
printf("%d %d\n",u,v);
}
return ;
}
1 second
256 megabytes
standard input
standard output
Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:
Max owns n creatures, i-th of them can be described with two numbers — its health hpi and its damage dmgi. Max also has two types of spells in stock:
- Doubles health of the creature (hpi := hpi·2);
- Assigns value of health of the creature to its damage (dmgi := hpi).
Spell of first type can be used no more than a times in total, of the second type — no more than b times in total. Spell can be used on a certain creature multiple times. Spells can be used in arbitrary order. It isn't necessary to use all the spells.
Max is really busy preparing for his final exams, so he asks you to determine what is the maximal total damage of all creatures he can achieve if he uses spells in most optimal way.
The first line contains three integers n, a, b (1 ≤ n ≤ 2·105, 0 ≤ a ≤ 20, 0 ≤ b ≤ 2·105) — the number of creatures, spells of the first type and spells of the second type, respectively.
The i-th of the next n lines contain two number hpi and dmgi (1 ≤ hpi, dmgi ≤ 109) — description of the i-th creature.
Print single integer — maximum total damage creatures can deal.
2 1 1
10 15
6 1
27
3 0 3
10 8
7 11
5 2
26
题意:你在打炉石玩脏牧,场上有n个单位。现在给你a张神圣之灵和b张心灵之火,让你营造出场上攻击总和最大的局面。并输出总攻击值。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define mod 1000000007
#define clr_1(x) memset(x,-1,sizeof(x))
#define INF 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pbk pop_back
using namespace std;
const int N=3e5+;
struct node
{
LL hp,dmg,xc;
}skil[N];
LL pre[N];
LL sum,t,k,a,b,mul,ans,tmp;
int n,m;
bool cmp(node a,node b)
{
return a.xc>b.xc;
}
int main()
{
scanf("%d%I64d%I64d",&n,&a,&b);
mul=<<a;
b=min(b,(LL)n);
sum=;
for(int i=;i<=n;i++)
{
scanf("%I64d%I64d",&skil[i].hp,&skil[i].dmg);
skil[i].xc=max(0LL,skil[i].hp-skil[i].dmg);
sum+=skil[i].dmg;
}
if(b==)
{
printf("%I64d\n",sum);
return ;
}
sort(skil+,skil+n+,cmp);
pre[]=;
for(int i=;i<=n;i++)
pre[i]=pre[i-]+skil[i].xc;
LL ans=sum+pre[b];
for(int i=;i<=n;i++)
{
tmp=sum-skil[i].dmg+skil[i].hp*mul;
if(i<=b)
tmp+=pre[b]-skil[i].xc;
else
tmp+=pre[b-];
ans=max(ans,tmp);
}
printf("%I64d\n",ans);
return ;
}
F. 最大流
Educational Codeforces Round 43 (Rated for Div. 2) ABCDE的更多相关文章
- 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 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
- Educational Codeforces Round 48 (Rated for Div. 2) CD题解
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms 题目链接:https://codeforce ...
随机推荐
- 原创:HTML 头像截取上传 JS+PHP 整合包~
关于: 关于头像上传这个东西,网上一搜乱七八糟的一堆然而很少很少有自己中意的插件一怒之下就自己写一个... 用法: <!DOCTYPE html> <html lang=" ...
- 天梯赛 L2-005 集合相似度 (set容器)
给定两个整数集合,它们的相似度定义为:Nc/Nt*100%.其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数.你的任务就是计算任意一对给定集合的相似度. 输入格式: 输 ...
- JSP分页之结合Bootstrap分页插件进行简单分页
结合Bootstrap的分页插件实现分页,其中策略是每次显示5个按钮,然后根据当前页的不同来进行不同的显示: 1. 当前页<3,如果当前页大于5页就显示前五页,不然就显示1~totalPage. ...
- 爬虫实战--基于requests 和 Beautiful的7160美图网爬取图片
import requests import os from bs4 import BeautifulSoup import re # 初始地址 all_url = 'http://www.7160. ...
- .ui/qrc文件自动生成.py文件
前天PL让我们做一个从手机里手机一些数据导出到excel文件里的Tool. 让我们用python去写一个.但是我们都没有学过python..呵呵! 然后昨天看了一些文档.做ui时还需要把图片写入qrc ...
- SpringMVC可以配置多个拦截后缀*.action和.do等
首先介绍一下.do和.action的区别: struts早期的1版本,以.do为后缀. 同时spring的MVC也是以.do为后缀. 几年前struts收购鼎鼎大名的webwork2和开发团队后,将w ...
- .NET Framework 4安装失败
#刚装系统遇到之前所遇到的问题.之前因为这个事情还被困扰了好一阵子.特此写出来分享给大家. 环境:WIN10 企业版 在使用一些需要较高.net版本的时候无法更新.你可以试一下.在服务里面开启再更新. ...
- SQLserver连接本地服务器
1.打开SQLserver “连接到服务器” 2.服务器类型:数据库引擎 3.服务器名称:浏览更多->本地服务器->数据库引擎->选择本地服务器 4.身份验证:windows验证 5 ...
- 014 JVM面试题
转自:http://www.importnew.com/31126.html 本文从 JVM 结构入手,介绍了 Java 内存管理.对象创建.常量池等基础知识,对面试中 JVM 相关的基础题目进行了讲 ...
- oracle只要第一条数据SQL
select * from ( select * from COMMON_BIZREL_WF where sponsor is not null order by serialid ) where r ...