修仙场,没脑子,C边界判错一直在写mdzz。。D根本没怎么想。

第二天起来想了想D这不是水题吗立马A了。看了看E一开始想分配问题后来发觉想岔了,只需要每次都把树最后分配的点移到最前面就好了。

A. Paper Airplanes
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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?

Input

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.

Output

Print a single integer — the minimum number of packs they should buy.

Examples
input

Copy
5 3 2 3
output

Copy
4
input

Copy
5 3 100 1
output

Copy
5
Note

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 ;
}
B. Battleship
time limit per test

1.5 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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

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.

Examples
input

Copy
4 3
#..#
#.#.
....
.###
output

Copy
3 2
input

Copy
10 4
#....##...
.#...#....
..#..#..#.
...#.#....
.#..##.#..
.....#...#
...#.##...
.#...#.#..
.....#..#.
...#.#...#
output

Copy
6 1
input

Copy
19 6
##..............###
#......#####.....##
.....#########.....
....###########....
...#############...
..###############..
.#################.
.#################.
.#################.
.#################.
#####....##....####
####............###
####............###
#####...####...####
.#####..####..#####
...###........###..
....###########....
.........##........
#.................#
output

Copy
1 8
Note

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 ;
}
C. Greedy Arkady
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
input

Copy
20 4 5 2
output

Copy
8
input

Copy
30 9 4 1
output

Copy
4
Note

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 ; }
D. Single-use Stones
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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?

Input

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.

Output

Print a single integer — the maximum number of frogs that can cross the river.

Examples
input

Copy
10 5
0 0 1 0 2 0 0 1 0
output

Copy
3
input

Copy
10 3
1 1 1 1 2 1 1 1 1
output

Copy
3
Note

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 ;
}
E. Short Code
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print a single integer — the minimum possible total length of new variable names.

Examples
input

Copy
3
codeforces
codehorses
code
output

Copy
6
input

Copy
5
abba
abb
ab
aa
aacada
output

Copy
11
input

Copy
3
telegram
digital
resistance
output

Copy
3
Note

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的更多相关文章

  1. Codeforces Round #476 (Div. 2) [Thanks, Telegram!] C

    http://codeforces.com/contest/965/problem/C 题目大意:n个糖,k个人,每次最多只能拿M个糖,从第一个人开始拿,可以循环D次.问Arkady最多可以拿几块糖? ...

  2. 【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] C】Greedy Arkady

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 枚举那个人收到了几次糖i. 最好的情况显然是其他人都只收到i-1次糖. 然后这个人刚好多收了一次糖 也即 (i-1)kx + x & ...

  3. 【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] E】Short Code

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 先建立一棵字典树. 显然,某一些节点上会被打上标记. 问题就转化成求所有标记的深度的和的最小值了. (标记可以上移,但是不能在同一位 ...

  4. 【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] D】Single-use Stones

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 设长度为L的所有区间里面,石头的个数的最小值为k 设取到k的区间为l,r 那么k就为最多能通过的青蛙个数. 假设k再大一点.比如为k ...

  5. 【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] A】Paper Airplanes

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 统计每个人需要的sheet个数. 乘上k 然后除p就是需要的pack个数了 [代码] #include <bits/stdc+ ...

  6. 【Codeforces Round #476 (Div. 2) [Thanks, Telegram!] B】Battleship

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 暴力枚举船的左上角. 然后统计每个点被覆盖次数就好. [代码] #include <bits/stdc++.h> #de ...

  7. 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 题解 直接 ...

  8. Codeforces Round #447 (Div. 2) 题解 【ABCDE】

    BC都被hack的人生,痛苦. 下面是题解的表演时间: A. QAQ "QAQ" is a word to denote an expression of crying. Imag ...

  9. Codeforces Round #408 (Div. 2) 题解【ABCDE】

    A - Buying A House 题意:给你n个房间,妹子住在第m个房间,你有k块钱,你想买一个离妹子最近的房间.其中相邻的房间之间距离为10,a[i]=0表示已经被别人买了. 题解:扫一遍更新答 ...

随机推荐

  1. HDU 2553 N皇后问题 (深搜)

    题目链接 Problem Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上. 你的任务是,对 ...

  2. java springmvc4 图片或文件上传

    1.文件配置 配置文件解析 上传文件处理的核心方法 // uploadOneFile.jsp, uploadMultiFile.jsp submit to. @RequestMapping(value ...

  3. js_页面关闭beforeunload事件

    做圆桌爆文公众号的时候,需要对阅读的文章进行时间统计.是这个公众号的核心功能,客户把文章转发到朋友圈或者转给朋友,记录谁阅读此文章和阅读时长进行记录,从而展示给客户. 功能点是,关闭页面时触发事件,请 ...

  4. Ribbon的主要组件与工作流程

    一:Ribbon是什么? Ribbon是Netflix发布的开源项目,主要功能是提供客户端的软件负载均衡算法,将Netflix的中间层服务连接在一起.Ribbon客户端组件提供一系列完善的配置项如连接 ...

  5. 广度优先算法(BFS)与深度优先算法(DFS)

    一.广度优先算法BFS(Breadth First Search) 基本实现思想 (1)顶点v入队列. (2)当队列非空时则继续执行,否则算法结束. (3)出队列取得队头顶点v: (4)查找顶点v的所 ...

  6. Lucene7.2.1系列(一)快速入门

    系列文章: Lucene系列(一)快速入门 Lucene系列(二)luke使用及索引文档的基本操作 Lucene系列(三)查询及高亮 Lucene是什么? Lucene在维基百科的定义 Lucene是 ...

  7. Perl6 Bailador框架(1):开始

    use v6; use Bailador; get '/' => sub { '<h1><center>Hello, World</center></h ...

  8. Python3 使用 urllib 编写爬虫

    什么是爬虫 爬虫,也叫蜘蛛(Spider),如果把互联网比喻成一个蜘蛛网,Spider就是一只在网上爬来爬去的蜘蛛.网络爬虫就是根据网页的地址来寻找网页的,也就是URL.举一个简单的例子,我们在浏览器 ...

  9. Python爬虫—破解JS加密的Cookie

    前言 在GitHub上维护了一个代理池的项目,代理来源是抓取一些免费的代理发布网站.上午有个小哥告诉我说有个代理抓取接口不能用了,返回状态521.抱着帮人解决问题的心态去跑了一遍代码.发现果真是这样. ...

  10. 【Python学习】matplotlib的颜色

    matplotlib自带的颜色 seaborn的颜色 装了seaborn扩展的话,在字典seaborn.xkcd_rgb中包含所有的xkcd crowdsourced color names. 使用的 ...