Codeforces Round #476 (Div. 2) [Thanks, Telegram!] ABCDE
修仙场,没脑子,C边界判错一直在写mdzz。。D根本没怎么想。
第二天起来想了想D这不是水题吗立马A了。看了看E一开始想分配问题后来发觉想岔了,只需要每次都把树最后分配的点移到最前面就好了。
1 second
256 megabytes
standard input
standard output
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make ss airplanes.
A group of kk people decided to make nn airplanes each. They are going to buy several packs of paper, each of them containing pp sheets, and then distribute the sheets between the people. Each person should have enough sheets to make nn airplanes. How many packs should they buy?
The only line contains four integers kk, nn, ss, pp (1≤k,n,s,p≤1041≤k,n,s,p≤104) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.
Print a single integer — the minimum number of packs they should buy.
5 3 2 3
4
5 3 100 1
5
In the first sample they have to buy 44 packs of paper: there will be 1212 sheets in total, and giving 22 sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets.
水题,推个小公式就好了。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
using namespace std;
int n,k,s,p;
int main()
{
scanf("%d%d%d%d",&k,&n,&s,&p);
printf("%d\n",(((n-)/s+)*k-)/p+);
return ;
}
1.5 seconds
256 megabytes
standard input
standard output
Arkady is playing Battleship. The rules of this game aren't really important.
There is a field of n×nn×n cells. There should be exactly one kk-decker on the field, i. e. a ship that is kk cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arkady knows if it is definitely empty or can contain a part of the ship.
Consider all possible locations of the ship. Find such a cell that belongs to the maximum possible number of different locations of the ship.
The first line contains two integers nn and kk (1≤k≤n≤1001≤k≤n≤100) — the size of the field and the size of the ship.
The next nn lines contain the field. Each line contains nn characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship).
Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship.
If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell.
4 3
#..#
#.#.
....
.###
3 2
10 4
#....##...
.#...#....
..#..#..#.
...#.#....
.#..##.#..
.....#...#
...#.##...
.#...#.#..
.....#..#.
...#.#...#
6 1
19 6
##..............###
#......#####.....##
.....#########.....
....###########....
...#############...
..###############..
.#################.
.#################.
.#################.
.#################.
#####....##....####
####............###
####............###
#####...####...####
.#####..####..#####
...###........###..
....###########....
.........##........
#.................#
1 8
The picture below shows the three possible locations of the ship that contain the cell (3,2)(3,2) in the first sample.
然后这题的话,就是统计下每个点向上、向下、向左、向右最长能达到的船体长度,然后最后算算每个点竖着(上下)这一维能有一部分是他的情况下有多少船,横着有多少船。由于包含自己,所以向上下左右最多延展k长度。因此超过k的算为k然后做个加减法就能算出包含这个点的船只数量。在每个点取最大点就是答案案。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define mod 1000000007
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e2+;
int a[N][N],up[N][N],lt[N][N],rt[N][N],down[N][N];
char s[N];
int n,m,k,t,sized,x,y,ans,p;
int main()
{
scanf("%d%d",&n,&sized);
for(int i=;i<=n;i++)
{
scanf("%s",s);
for(int j=;j<n;j++)
if(s[j]=='.')
a[i][j+]=;
}
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(a[i][j])
{
lt[i][j]=lt[i][j-]+;
up[i][j]=up[i-][j]+;
} for(int i=n;i>=;i--)
for(int j=n;j>=;j--)
if(a[i][j])
{
rt[i][j]=rt[i][j+]+;
down[i][j]=down[i+][j]+;
}
ans=;
x=y=;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(a[i][j])
{
p=;
if(min(lt[i][j],sized)+min(rt[i][j],sized)>sized)
p+=min(lt[i][j],sized)+min(rt[i][j],sized)-sized;
if(min(up[i][j],sized)+min(down[i][j],sized)>sized)
p+=min(up[i][j],sized)+min(down[i][j],sized)-sized;
if(p>ans)
{
ans=p;
x=i;
y=j;
}
}
printf("%d %d\n",x,y);
return ;
}
1 second
256 megabytes
standard input
standard output
kk people want to split nn candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from 11 to kk, and Arkady is the first of them. To split the candies, Arkady will choose an integer xx and then give the first xx candies to himself, the next xx candies to the second person, the next xx candies to the third person and so on in a cycle. The leftover (the remainder that is not divisible by xx) will be thrown away.
Arkady can't choose xx greater than MM as it is considered greedy. Also, he can't choose such a small xx that some person will receive candies more than DD times, as it is considered a slow splitting.
Please find what is the maximum number of candies Arkady can receive by choosing some valid xx.
The only line contains four integers nn, kk, MM and DD (2≤n≤10182≤n≤1018, 2≤k≤n2≤k≤n, 1≤M≤n1≤M≤n, 1≤D≤min(n,1000)1≤D≤min(n,1000), M⋅D⋅k≥nM⋅D⋅k≥n) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can receive candies.
Print a single integer — the maximum possible number of candies Arkady can give to himself.
Note that it is always possible to choose some valid xx.
20 4 5 2
8
30 9 4 1
4
In the first example Arkady should choose x=4x=4. He will give 44 candies to himself, 44 candies to the second person, 44 candies to the third person, then 44 candies to the fourth person and then again 44 candies to himself. No person is given candies more than 22 times, and Arkady receives 88 candies in total.
Note that if Arkady chooses x=5x=5, he will receive only 55 candies, and if he chooses x=3x=3, he will receive only 3+3=63+3=6 candies as well as the second person, the third and the fourth persons will receive 33 candies, and 22 candies will be thrown away. He can't choose x=1x=1 nor x=2x=2 because in these cases he will receive candies more than 22 times.
In the second example Arkady has to choose x=4x=4, because any smaller value leads to him receiving candies more than 11 time.
果然二分保平安,由于本傻子错想一个公式确定了x的左边界,而这个公式是错的导致我一直没过题。二分保平安,以后二分确定边界了。。。然后这题的话题目告诉你D≤1000,那你枚举分配轮数就好了。设总共进行了t+1轮,那么第一个人在总共t+1轮分到最多的是什么情况呢?那当然是第t+1轮第一次分给他糖果之后,剩下糖果最少的时候他分到最多。因此我们每一轮最多的x由n/(tk+1)得出。超边界就不计算他。然后答案就在左边界,右边界以及每一轮分到最多的情况中诞生。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define mod 1000000007
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
LL n,k,m,d,lt,rt,l,r,p,t,pt;
LL ans=INF;
LL search(LL n,LL k,LL m,LL d)
{
LL lt=,rt=m,p,mid;
while(lt!=rt)
{
mid=(lt+rt)>>;
p=(n-)/k/mid+;
if(p<=d)
rt=mid;
else
lt=mid+;
}
return lt;
}
int main()
{
scanf("%I64d%I64d%I64d%I64d",&n,&k,&m,&d);
rt=m;
lt=search(n,k,m,d);
l=n/k/rt;
ans=;
ans=max(((n/lt-)/k+)*lt,((n/rt-)/k+)*rt);
for(LL i=l;i<=d;i++)
{
p=n/(i*k+);
if(p>rt)
continue;
if(p<lt)
break;
ans=max(ans,((n/p-)/k+)*p);
}
printf("%I64d\n",ans);
return ; }
1 second
256 megabytes
standard input
standard output
A lot of frogs want to cross a river. A river is ww units width, but frogs can only jump ll units long, where l<wl<w. Frogs can also jump on lengths shorter than ll. but can't jump longer. Hopefully, there are some stones in the river to help them.
The stones are located at integer distances from the banks. There are aiai stones at the distance of ii units from the bank the frogs are currently at. Each stone can only be used once by one frog, after that it drowns in the water.
What is the maximum number of frogs that can cross the river, given that then can only jump on the stones?
The first line contains two integers ww and ll (1≤l<w≤1051≤l<w≤105) — the width of the river and the maximum length of a frog's jump.
The second line contains w−1w−1 integers a1,a2,…,aw−1a1,a2,…,aw−1 (0≤ai≤1040≤ai≤104), where aiai is the number of stones at the distance ii from the bank the frogs are currently at.
Print a single integer — the maximum number of frogs that can cross the river.
10 5
0 0 1 0 2 0 0 1 0
3
10 3
1 1 1 1 2 1 1 1 1
3
In the first sample two frogs can use the different stones at the distance 55, and one frog can use the stones at the distances 33 and then 88.
In the second sample although there are two stones at the distance 55, that does not help. The three paths are: 0→3→6→9→100→3→6→9→10, 0→2→5→8→100→2→5→8→10, 0→1→4→7→100→1→4→7→10.
我的想法是用最小割最大流定理去想(贪)。
不可避免的,如果最多有k只到对岸,选择任意一个位置 $ i $,以位置$i$前面的任意一个位置为源点,一步越过位置$i$的流量总和 $flow[i]≥k$。那这个流量总和 $ flow[i] $ 就是 $ [i-l+1,i] $ 的石头总数 $ sum[i-l+1,i] $。而答案明显就是这些流量总和中最小的那个。因此求个前缀和,然后$O(w) $地遍历一遍找最小的一个 $ sum[i-l+1,i] $ 即为答案。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define mod 1000000007
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+;
int a[N],pre[N];
int n,l;
int ans;
int main()
{
ans=INF;
scanf("%d%d",&n,&l);
for(int i=;i<n;i++)
scanf("%d",a+i);
for(int i=;i<n;i++)
pre[i]=pre[i-]+a[i];
for(int i=l;i<n;i++)
ans=min(pre[i]-pre[i-l],ans);
printf("%d\n",ans);
return ;
}
1 second
256 megabytes
standard input
standard output
Arkady's code contains nn variables. Each variable has a unique name consisting of lowercase English letters only. One day Arkady decided to shorten his code.
He wants to replace each variable name with its non-empty prefix so that these new names are still unique (however, a new name of some variable can coincide with some old name of another or same variable). Among such possibilities he wants to find the way with the smallest possible total length of the new names.
A string aa is a prefix of a string bb if you can delete some (possibly none) characters from the end of bb and obtain aa.
Please find this minimum possible total length of new names.
The first line contains a single integer nn (1≤n≤1051≤n≤105) — the number of variables.
The next nn lines contain variable names, one per line. Each name is non-empty and contains only lowercase English letters. The total length of these strings is not greater than 105105. The variable names are distinct.
Print a single integer — the minimum possible total length of new variable names.
3
codeforces
codehorses
code
6
5
abba
abb
ab
aa
aacada
11
3
telegram
digital
resistance
3
In the first example one of the best options is to shorten the names in the given order as "cod", "co", "c".
In the second example we can shorten the last name to "aac" and the first name to "a" without changing the other names.
那最后一题则是一个想法题。
先写个trie,那么每个字符串对应trie一个节点,并且我们标记这样的节点。那么我们的任务是通过上移标记让这些标记节点深度总和最小。我们dfs一下。假如在节点u,我们先处理出u子树所有节点标记的深度。如果u没有被标记,那么我们把最深的一个节点的标记上移到u节点。这样不断贪心得出的答案是最优的。那么我们对每个点写一个优先队列来维护标记节点的深度,移动标记就相当于把优先队列深度最高的出队,然后把该节点u的深度入队。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define mod 1000000007
#define LL long long
#define INF 0x3f3f3f3f
#define pb(x) push_back(x)
using namespace std;
const int N=1e5+;
const int type=;
char s[N];
int n,m,k;
struct node
{
int next[type],num;
}trie[N];
priority_queue<int> slen[N];
int ans,ct,tot;
int makenode()
{
tot++;
memset(&trie[tot],,sizeof(trie[tot]));
return tot;
}
void init()
{
tot=-;
makenode();
ans=;
return ;
}
void add(char *s)
{
int now=,p;
int len=strlen(s);
for(int i=;s[i];i++)
{
p=s[i]-'a';
if(!trie[now].next[p])
trie[now].next[p]=makenode();
now=trie[now].next[p];
}
trie[now].num++;
return ;
}
void dfs(int now,int dep)
{
int p;
for(int i=;i<type;i++)
{
p=trie[now].next[i];
if(p)
{
dfs(p,dep+);
if(slen[p].size()>slen[now].size()) slen[p].swap(slen[now]);
while(!slen[p].empty())
{
slen[now].push(slen[p].top());
slen[p].pop();
}
}
}
if(trie[now].num==)
{
slen[now].pop();
slen[now].push(dep);
}
else
slen[now].push(dep);
return ;
}
int main()
{
scanf("%d",&n);
init();
for(int i=;i<=n;i++)
{
scanf("%s",s);
add(s);
}
for(int i=;i<type;i++)
if(trie[].next[i])
{
k=trie[].next[i];
dfs(k,);
while(!slen[k].empty())
{
ans+=slen[k].top();
slen[k].pop();
}
}
printf("%d\n",ans);
return ;
}
Codeforces Round #476 (Div. 2) [Thanks, Telegram!] ABCDE的更多相关文章
- Codeforces Round #476 (Div. 2) [Thanks, Telegram!] C
http://codeforces.com/contest/965/problem/C 题目大意:n个糖,k个人,每次最多只能拿M个糖,从第一个人开始拿,可以循环D次.问Arkady最多可以拿几块糖? ...
- 【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] C】Greedy Arkady
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举那个人收到了几次糖i. 最好的情况显然是其他人都只收到i-1次糖. 然后这个人刚好多收了一次糖 也即 (i-1)kx + x & ...
- 【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] E】Short Code
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 先建立一棵字典树. 显然,某一些节点上会被打上标记. 问题就转化成求所有标记的深度的和的最小值了. (标记可以上移,但是不能在同一位 ...
- 【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] D】Single-use Stones
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 设长度为L的所有区间里面,石头的个数的最小值为k 设取到k的区间为l,r 那么k就为最多能通过的青蛙个数. 假设k再大一点.比如为k ...
- 【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] A】Paper Airplanes
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 统计每个人需要的sheet个数. 乘上k 然后除p就是需要的pack个数了 [代码] #include <bits/stdc+ ...
- 【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] B】Battleship
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 暴力枚举船的左上角. 然后统计每个点被覆盖次数就好. [代码] #include <bits/stdc++.h> #de ...
- Codeforces Round #383 (Div. 2) 题解【ABCDE】
Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...
- Codeforces Round #447 (Div. 2) 题解 【ABCDE】
BC都被hack的人生,痛苦. 下面是题解的表演时间: A. QAQ "QAQ" is a word to denote an expression of crying. Imag ...
- Codeforces Round #408 (Div. 2) 题解【ABCDE】
A - Buying A House 题意:给你n个房间,妹子住在第m个房间,你有k块钱,你想买一个离妹子最近的房间.其中相邻的房间之间距离为10,a[i]=0表示已经被别人买了. 题解:扫一遍更新答 ...
随机推荐
- 【比赛】STSRM 09
第一题 题意:n个点,每个点坐标pi属性ai,从右往左将遇到的点向左ai范围内的点消除,后继续扫描. 现可以在扫描开始前提前消除从右往左任意点,问最少消除数(提前+扫描). n,pi,ai<=1 ...
- 【HDU】6012 Lotus and Horticulture (BC#91 T2)
[算法]离散化 [题解] 答案一定存在于区间的左右端点.与区间左右端点距离0.5的点上 于是把所有坐标扩大一倍,排序(即离散化). 让某个点的前缀和表示该点的答案. 初始sum=∑c[i] 在l[i] ...
- 2017-2018-1 20179205《Linux内核原理与设计》第四周作业
<Linux内核原理与分析> 视频学习及实验操作 Linux内核源代码 视频中提到了三个我们要重点专注的目录下的代码,一个是arch目录下的x86,支持不同cpu体系架构的源代码:第二个是 ...
- 增大dma的分配
前言 项目中需要通过驱动与fpga通讯,获取fpga往内存里写的数据.因为数据量比较大,需要驱动分配600多M的内存给fpga来写数据,且因为是与fpga通讯,需要连续的内存,还得是uncached的 ...
- java===java基础学习(4)---字符串操作
java中的字符串操作和python中的大致相同,需要熟悉的就是具体操作形式. 关于具体api的使用,详见:java===字符串常用API介绍(转) package testbotoo; public ...
- Html Css 练习
一. 取消a链接的下划线 <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...
- maven设置打jar包并引入依赖包
--------------------------------------------------------方法一:将jar包和项目打在一起---------------------------- ...
- layui文件单文件和多文件的上传、预览以及删除和修改
活不多说,直接上代码 单文件上传 1.HTML <blockquote class="layui-elem-quote layui-quote-nm" style=" ...
- System.Web.HttpContext.Current.Request用法
public static void SetRegisterSource() { if (System.Web.HttpContext.Current.Request["website&qu ...
- Linux下GCC相关知识点
摘要: 总结GCC的具体使用,动态库静态库的相关问题 参考资料: <Linux网络编程> ISBN:9787302207177 p19 1 GCC简介 GCC是Linux下的编译工具集,是 ...