修仙场,没脑子,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. luaj luaoc 回调函数传递的一些小总结

    问题场景:我们的游戏在支付时,由于第三方支付比较费时,可能在支付的过程中,我们lua写的cocos2dx项目会断网,我们的游戏有自动重连的机制.我就想,如果断线好了以后,支付完成了,那在断网之前传入的 ...

  2. [Unity]多线程编程的一点心得

    在做毕设的时候涉及到了较大数据的读取,每次从硬盘读都会卡很久,于是找资料之后自己做了个简单的多线程解决方案. 一共有两个类.第一个类ThreadJob如下: using System.Collecti ...

  3. Spring 路由地址的基本使用

    1.下面是spring的使用基本框架连接 https://www.cnblogs.com/HD/p/4103239.html

  4. 一个简单插件this传值的跟踪

    <!DOCUTYPE html> <html> <head> <meta charset="UTF-8"> <script s ...

  5. NOI2018游记&我的OI历程

    day1 今天是报到日,坐着早上9点的飞机到了长沙,午饭时间到达雅礼洋湖. 宿舍还是一模一样,虽然是在女生宿舍. wifi信号还是一样的德行,刻意避开了宿舍内,只好把手机放在窗台上开热点. 饭菜还是如 ...

  6. python之提速千倍爆破一句话

    看了一下冰河大佬写的文章特别有感:https://bbs.ichunqiu.com/thread-16952-1-1.html 简单描述一下: 利用传统的单数据提交模式. 比如下面这个一句话木马: & ...

  7. 配置连接的IP、端口、以及相应的数据库

    解压后里面有:lib 源文件 .examples 例子.test测试 将lib目录拷贝到你的项目中,就可以开始你的predis操作了. //使用autoload加载相关库,这边重点就是为了requir ...

  8. C基础 工程中常用的排序

    引言 - 从最简单的插入排序开始 很久很久以前, 也许都曾学过那些常用的排序算法. 那时候觉得计算机算法还是有点像数学. 可是脑海里常思考同类问题, 那有什么用呢(屌丝实践派对装逼学院派的深情鄙视). ...

  9. vim常用命令(复习版)(转)

    原文链接:http://blog.csdn.net/love__coder/article/details/6739670 1.光标移动 上:k 下:j 左:l 『字母L小写』 右:h 上一行行首:- ...

  10. Linux 基础——处理文件与目录的命令

    继续第三天学习,每天下班后积累一点点,始终相信厚积薄发. 一.处理文件的命令 touch dest_file:在当前目录下创建指定的文件. cp source dest:将指定的猿文件复制到目标文件, ...