Codeforces Round #467 (Div. 2)【A B C D】

本文介绍了四个编程竞赛题目,涉及选择获奖者、寻找特定数值、计算烹饪时间及游戏策略等,通过算法解决实际问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A - Olympiad

The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
At least one participant should get a diploma.
None of those with score equal to zero should get awarded.
When someone is awarded, all participants with score not less than his score should also be awarded.
Determine the number of ways to choose a subset of participants that will receive the diplomas.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of participants.
The next line contains a sequence of n integers a1, a2, …, an (0 ≤ ai ≤ 600) — participants’ scores.
It’s guaranteed that at least one participant has non-zero score.
Output
Print a single integer — the desired number of ways.
Example
Input
4
1 3 3 2
Output
3
Input
3
1 1 1
Output
1
Input
4
42 0 0 42
Output
1
Note
There are three ways to choose a subset in sample case one.
Only participants with 3 points will get diplomas.
Participants with 2 or 3 points will get diplomas.
Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero scores cannot get anything.

题意:给你n个人的成绩,划分分数线(大于0)使等级不一样,求划分方法总数;
分析:成绩非0的种类数;

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 110;
int a[MAXN];

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    sort(a, a + n);
    int ans = unique(a, a + n) - a; //去重
    if(a[0] == 0) ans--;
    printf("%d\n", ans);
    return  0;
} 

B - Vile Grasshoppers

The weather is fine today and hence it’s high time to climb the nearby pine and enjoy the landscape.
The pine’s trunk includes several branches, located one above another and numbered from 2 to y. Some of them (more precise, from 2 to p) are occupied by tiny vile grasshoppers which you’re at war with. These grasshoppers are known for their awesome jumping skills: the grasshopper at branch x can jump to branches .
Keeping this in mind, you wisely decided to choose such a branch that none of the grasshoppers could interrupt you. At the same time you wanna settle as high as possible since the view from up there is simply breathtaking.
In other words, your goal is to find the highest branch that cannot be reached by any of the grasshoppers or report that it’s impossible.
Input
The only line contains two integers p and y (2 ≤ p ≤ y ≤ 109).
Output
Output the number of the highest suitable branch. If there are none, print -1 instead.
Example
Input
3 6
Output
5
Input
3 4
Output
-1
Note
In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case.

题意:输入p,y,输出最大的一个小于y的数,满足不能被2~p整除;
分析:
暴力y–,分解质因子判断是否全大于p即可;

#include <bits/stdc++.h>
using namespace std;
int y, p;

inline bool get_p(int x) {
    for(int i = 2; i * i <= x; i++) {
        if(x % i == 0) {
            if(i <= p) return false;
            while(x % i == 0) {
                x /= i;
            }
        }
    }
    if(x > 1 && x <= p) return false;
    return true;
} 

int main() {
    scanf("%d %d", &p, &y);
    for(int i = y; i > p; i--) {
        bool flag = get_p(i);
        if(flag) {
            printf("%d\n", i);
            return 0;
        }
    } 
    printf("-1\n");
    return 0;
} 

C - Save Energy!

Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.
During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.
It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.
Input
The single line contains three integers k, d and t (1 ≤ k, d, t ≤ 1018).
Output
Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9.
Namely, let’s assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if .
Example
Input
3 2 6
Output
6.5
Input
4 2 20
Output
20.0
Note
In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for . Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for . Thus, after four minutes the chicken will be cooked for . Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready .
In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.

题意:一锅水,需要t分钟全速加热才能煮熟。一个加热器,k分钟全速加热,k分钟后熄火由于保温效果半速加热,一个人每隔d分钟检查一遍加热器是否熄火;
分析:算k+d/2在t时间内的周期,剩余部分在特判一下即可,分数没有取余,我用二分直接找的。因为只有除2操作,公式变换一下乘2应该也行;

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int MAXN = 110;
double ans, cnt, sum;
LL k, d, t, ant;

inline void find() {
    LL L = 0, R = 1e18 + 1;
    while(L < R - 1) {
        LL mid = (L + R) >> 1;
        double res = double(mid) * ans;
        if(res <= double(t)) L = mid;
        else R = mid;
    }
    sum = double(ant) * double(L);
    cnt = double(t) - ans * double(L);
}

int main() {
    scanf("%lld %lld %lld", &k, &d, &t);
    ant = (k / d + ((k % d) ? 1 : 0)) * d;
    ans = double(k) + (double((d - (k % d)) % d)) / 2.0;
    find();
//  printf("%lld\n", ant);
//  printf("sum:%lf cnt:%lf ans:%lf\n", sum, cnt, ans);
    if(cnt <= double(k)) sum += cnt;
    else sum += k + (cnt - double(k)) * 2; //这一步别加重了
    printf("%lf\n", sum);
    return  0;
} 

D - Sleepy Game

Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of n vertices and m edges. One of the vertices contains a chip. Initially the chip is located at vertex s. Players take turns moving the chip along some edge of the graph. Petya goes first. Player who can’t move the chip loses. If the game lasts for 106 turns the draw is announced.
Vasya was performing big laboratory work in “Spelling and parts of speech” at night before the game, so he fell asleep at the very beginning of the game. Petya decided to take the advantage of this situation and make both Petya’s and Vasya’s moves.
Your task is to help Petya find out if he can win the game or at least draw a tie.
Input
The first line of input contain two integers n and m — the number of vertices and the number of edges in the graph (2 ≤ n ≤ 105, 0 ≤ m ≤ 2·105).
The next n lines contain the information about edges of the graph. i-th line (1 ≤ i ≤ n) contains nonnegative integer ci — number of vertices such that there is an edge from i to these vertices and ci distinct integers ai, j — indices of these vertices (1 ≤ ai, j ≤ n, ai, j ≠ i).
It is guaranteed that the total sum of ci equals to m.
The next line contains index of vertex s — the initial position of the chip (1 ≤ s ≤ n).
Output
If Petya can win print «Win» in the first line. In the next line print numbers v1, v2, …, vk (1 ≤ k ≤ 106) — the sequence of vertices Petya should visit for the winning. Vertex v1 should coincide with s. For i = 1… k - 1 there should be an edge from vi to vi + 1 in the graph. There must be no possible move from vertex vk. The sequence should be such that Petya wins the game.
If Petya can’t win but can draw a tie, print «Draw» in the only line. Otherwise print «Lose».
Example
Input
5 6
2 2 3
2 4 5
1 4
1 5
0
1
Output
Win
1 2 4 5
Input
3 2
1 3
1 1
0
2
Output
Lose
Input
2 2
1 2
1 1
1
Output
Draw

题意:一张有向图,给你一个起点,让你从起点出发,判断是否存在奇数边的一条路(从起点到尽头的路);
分析:开始我直接二分图染色暴力写了,存在横向边没判,判了横向边和环之后,又wa+TLE;
二分图染色,很灵性的操作:vis[u][step ^ 1]来保存路径染色状况,pre并查集维护路径步骤。注意一点,有可能存在环还需要继续搜,因为可能是奇数环,就能改变胜负了,所以输出路径的时候就判断一下当路过起点时的状态,有可能走了一个奇数环又回来了;

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int MAXN = 1e5 + 5;
int pre[MAXN][2], col[MAXN], vis[MAXN][2], in[MAXN];
vector<int> G[MAXN];
bool Lose = false, Win = false, Draw = false;
int n, m, st, p = 0;

inline void dfs(int x, int step) {
    for(int i = 0; i < G[x].size(); ++i) {
        int u = G[x][i];
        if(col[u]) Draw = true; //注意这一点,不要剪,有可能存在路径 
        if(vis[u][step ^ 1]) continue;
        vis[u][step ^ 1] = 1;
        pre[u][step ^ 1] = x; //记录路径 
        col[u] = 1;           //判断是否存在环 
        dfs(u, step ^ 1);
        col[u] = 0;
    }
}

int main() {
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; ++i) {
        int t, x;
        scanf("%d", &t);
        while(t--) {
            scanf("%d", &x);
            G[i].push_back(x);
        }
    }
    scanf("%d", &st);
    vis[st][0] = 0;
    col[st] = 1;
    dfs(st, 0);
    for(int i = 1; i <= n; ++i) {
        if(G[i].size() == 0 && vis[i][1]) {
            puts("Win");
            int last = i, tt = 1;
            while(last != st || tt) { //tt为真,有可能绕一圈回到原点,此时该后手行走 
                in[p++] = last;
                last = pre[last][tt];
                tt ^= 1;
            }
            in[p++] = st;
            for(int j = p - 1; j > 0; j--) {
                printf("%d ", in[j]);
            }
            printf("%d\n", in[0]);
            return 0;
        }
    }
    if(Draw) puts("Draw");
    else puts("Lose");
    return  0;
} 

/*
3 100
1 2
1 3
1 1
1

5 100
2 2 3
1 5
1 4
1 5
0
1
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值