Codeforces Round #630 (Div. 2) (补比赛)

今天周四,没怎么有课,实在闲得慌,而且好久也没有写代码了........能力直线下降,就跟没过纳斯达克的股票一样.....

上一篇博客是四月九号发的,唉,简直了.....

A. Ichihime and Triangle

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Ichihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears.

These days the temple is holding a math contest. Usually, Ichihime lacks interest in these things, but this time the prize for the winner is her favorite — cookies. Ichihime decides to attend the contest. Now she is solving the following problem.

You are given four positive integers aa, bb, cc, dd, such that a≤b≤c≤da≤b≤c≤d.

Your task is to find three integers xx, yy, zz, satisfying the following conditions:

  • a≤x≤ba≤x≤b.
  • b≤y≤cb≤y≤c.
  • c≤z≤dc≤z≤d.
  • There exists a triangle with a positive non-zero area and the lengths of its three sides are xx, yy, and zz.

Ichihime desires to get the cookie, but the problem seems too hard for her. Can you help her?

Input

The first line contains a single integer tt (1≤t≤10001≤t≤1000)  — the number of test cases.

The next tt lines describe test cases. Each test case is given as four space-separated integers aa, bb, cc, dd (1≤a≤b≤c≤d≤1091≤a≤b≤c≤d≤109).

Output

For each test case, print three integers xx, yy, zz  — the integers you found satisfying the conditions given in the statement.

It is guaranteed that the answer always exists. If there are multiple answers, print any.

Example

input

4
1 3 5 7
1 5 5 7
100000 200000 300000 400000
1 1 977539810 977539810

output
3 4 5
5 5 5
182690 214748 300999
1 977539810 977539810

Note

One of the possible solutions to the first test case:

One of the possible solutions to the second test case:

//
// Created by DELL on 2020/4/23.
// 题目大意   :  a≤x≤b b≤y≤c c≤z≤d  使得xyz可以组成一个三角形     多组答案给出之一就行
//

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main(int argc,char* argv[]) {
    int T ,a,c,b,d; scanf("%d",&T);
    while(T--) {
        scanf("%d%d%d%d",&a,&b,&c,&d);
        printf("%d %d %d\n",b,c,c);
    }

    return 0;
}

B. Kana and Dragon Quest game

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic.

One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon.

c7715ea18024283ae27dcab024db999e77f34037.pnguploading.4e448015.gif转存失败重新上传取消

The dragon has a hit point of xx initially. When its hit point goes to 00 or under 00, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.

  • Void Absorption

    Assume that the dragon's current hit point is hh, after casting this spell its hit point will become ⌊h2⌋+10⌊h2⌋+10. Here ⌊h2⌋⌊h2⌋ denotes hh divided by two, rounded down.

  • Lightning Strike

    This spell will decrease the dragon's hit point by 1010. Assume that the dragon's current hit point is hh, after casting this spell its hit point will be lowered to h−10h−10.

Due to some reasons Kana can only cast no more than nn Void Absorptions and mm Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.

Input

The first line contains a single integer tt (1≤t≤10001≤t≤1000)  — the number of test cases.

The next tt lines describe test cases. For each test case the only line contains three integers xx, nn, mm (1≤x≤1051≤x≤105, 0≤n,m≤300≤n,m≤30)  — the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.

Output

If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes).

You can print each letter in any case (upper or lower).

Example

input

Copy

7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2

output

Copy

YES
NO
NO
YES
YES
YES
YES

Note

One possible casting sequence of the first test case is shown below:

  • Void Absorption ⌊1002⌋+10=60⌊1002⌋+10=60.
  • Lightning Strike 60−10=5060−10=50.
  • Void Absorption ⌊502⌋+10=35⌊502⌋+10=35.
  • Void Absorption ⌊352⌋+10=27⌊352⌋+10=27.
  • Lightning Strike 27−10=1727−10=17.
  • Lightning Strike 17−10=717−10=7.
  • Lightning Strike 7−10=−37−10=−3.

题目大意:

现在我们有一条龙,它的血量为 xx 。

我们有两个技能:雷击和空洞吸收。

雷击:

攻击后使得龙的血量减 1010 ,也就是说,原来 hh 的血量变为了 h - 10h−10 。

空洞吸收:

攻击后使得龙的血量变为:[\frac{h}{2}]+10[2h​]+10 ,其中 [h][h] 表示向下取整。

现在要知道是否可以在技能有使用次数的限制下打倒龙。

//
// Created by DELL on 2020/4/23.
//

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main(int argc,char* argv[]) {
    int T,x,n,m;
    scanf("%d",&T);
    while(T--) {
        scanf("%d %d %d",&x,&n,&m);
        for(int i=1; i<=n; i++) {
            if((x >> 1) + 10 > x) break;
            x = (x >> 1) + 10;
        }
        if(x <= m * 10) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C. Linova and Kingdom

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.

df63f4ac458c231c1258e895434dcb4c2f090f09.pnguploading.4e448015.gif正在上传…重新上传取消

There are nn cities and n−1n−1 two-way roads connecting pairs of cities in the kingdom. From any city, you can reach any other city by walking through some roads. The cities are numbered from 11 to nn, and the city 11 is the capital of the kingdom. So, the kingdom has a tree structure.

As the queen, Linova plans to choose exactly kk cities developing industry, while the other cities will develop tourism. The capital also can be either industrial or tourism city.

A meeting is held in the capital once a year. To attend the meeting, each industry city sends an envoy. All envoys will follow the shortest path from the departure city to the capital (which is unique).

Traveling in tourism cities is pleasant. For each envoy, his happiness is equal to the number of tourism cities on his path.

In order to be a queen loved by people, Linova wants to choose kk cities which can maximize the sum of happinesses of all envoys. Can you calculate the maximum sum for her?

Input

The first line contains two integers nn and kk (2≤n≤2⋅1052≤n≤2⋅105, 1≤k<n1≤k<n)  — the number of cities and industry cities respectively.

Each of the next n−1n−1 lines contains two integers uu and vv (1≤u,v≤n1≤u,v≤n), denoting there is a road connecting city uu and city vv.

It is guaranteed that from any city, you can reach any other city by the roads.

Output

Print the only line containing a single integer  — the maximum possible sum of happinesses of all envoys.

Examples

input

Copy

7 4
1 2
1 3
1 4
3 5
3 6
4 7

output

Copy

7

input

Copy

4 1
1 2
1 3
2 4

output

Copy

2

input

Copy

8 5
7 5
1 7
6 1
3 7
8 3
2 1
4 5

output

Copy

9

Note

In the first example, Linova can choose cities 22, 55, 66, 77 to develop industry, then the happiness of the envoy from city 22 is 11, the happiness of envoys from cities 55, 66, 77 is 22. The sum of happinesses is 77, and it can be proved to be the maximum one.

In the second example, choosing cities 33, 44 developing industry can reach a sum of 33, but remember that Linova plans to choose exactly kk cities developing industry, then the maximum sum is 22.

题目大意:

给定 nn 个节点的有根树,根是 11 号节点。

你可以选择 kk 个节点将其设置为工业城市,其余设置为旅游城市。

对于一个工业城市,定义它的幸福值为工业城市到根的路径经过的旅游城市的数量。

你需要求出所有工业城市的幸福值之和的最大可能值。

第一反应的思路肯定是按照深度来贪心,优先选深的,然后你会发现甚至过不了样例,因为可能某一个点虽然很深,但它的儿子很多,所以你选了他之后,他所有儿子的贡献都要减一,可能该选择不如选另一条分支上一个比他浅的点优。

所以在此基础上稍加改变,也就是由于实际上选一个点对答案的贡献是:1、增加了一个深度那么大的值;2、减少了一个儿子数那么多的值。所以,我们对树上的ii号节点,记录dep[i]−son[i],这才是选择某个点的真正贡献,贪心的选择该值大的i即可。当然,上面的“2”中其实隐含了另一个贪心性质,也就是最优解中某个节点被选择时其所有的儿子一定已经先被选择了,而这是好证的,因为否则的话,我们就可以选择其一个未被选择的儿子,得到更优的结果。

还有就是这题居然卡int,换long long AC

//
// Created by DELL on 2020/4/23.
//
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#define Maxn 200005
using namespace std;
int head[Maxn],tot,dep[Maxn],son[Maxn];
struct Edge{
    int nxt,to;
}e[Maxn << 2];

inline void Add_Edge(int u,int v) {
    e[++tot].to = v,e[tot].nxt = head[u]; head[u] = tot;
}

int DFS(int u,int fa,int depth) {
    dep[u] = depth;
    int ret = 0;
    for(int i=head[u]; i; i=e[i].nxt) {
        int v = e[i].to;
        if(v != fa) ret += DFS(v,u,depth + 1);
    }
    son[u] = ret;
    return ret + 1;
}

int main(int argc,char* argv[]) {
    int n,k; scanf("%d %d",&n,&k);
    for(int u,v,i=1; i<=n-1; i++) {
        scanf("%d %d",&u,&v);
        Add_Edge(u,v);
        Add_Edge(v,u);
    }
    DFS(1,1,0);
    for(int i=1; i<=n; i++) dep[i] -= son[i];
    sort(dep + 1,dep + 1 + n);
    long long Ans = 0;
    for(int i=n; i>=n-k+1; i--) Ans += dep[i];
    printf("%lld",Ans);
    return 0;
}

做到这里,额emmmmmm,这一期的Div2 还是比较简单的呢

猜你喜欢

转载自blog.csdn.net/qq_35776409/article/details/105699114