Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)

Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)

大家好,又见面了,我是全栈君。

A. Trip For Meal
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit’s and Owl’s houses is a meters, between Rabbit’s and Eeyore’s house is b meters, between Owl’s and Eeyore’s house is c meters.

For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal n times a day. Now he is in the Rabbit’s house and has a meal for the first time. Each time when in the friend’s house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend’s house, the supply of honey in other friend’s houses recover (most probably, they go to the supply store).

Winnie-the-Pooh does not like physical activity. He wants to have a meal n times, traveling minimum possible distance. Help him to find this distance.

Input

First line contains an integer n (1 ≤ n ≤ 100) — number of visits.

Second line contains an integer a (1 ≤ a ≤ 100) — distance between Rabbit’s and Owl’s houses.

Third line contains an integer b (1 ≤ b ≤ 100) — distance between Rabbit’s and Eeyore’s houses.

Fourth line contains an integer c (1 ≤ c ≤ 100) — distance between Owl’s and Eeyore’s houses.

Output

Output one number — minimum distance in meters Winnie must go through to have a meal n times.

Examples
input
3
2
3
1

output
3

input
1
2
3
5

output
0

Note

In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit’s house, then in Owl’s house, then in Eeyore’s house. Thus he will pass the distance 2 + 1 = 3.

In the second test case Winnie has a meal in Rabbit’s house and that is for him. So he doesn’t have to walk anywhere at all.

有一个三角形的图,你被固定在某点,要游历n次,首先n==1的时候肯定是0,n==2就选一个离这个点近的

可以两个点来回跑,那就第二次之后选择最近的点啊

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,c;
    cin>>n>>a>>b>>c;
    if(n==1)
        printf("0");
    else if(n==2)
        printf("%d",min(a,b));
    else printf("%d",min(a,b)+(n-2)*min(a,min(b,c)));
    return 0;
}

B. Divisiblity of Differences
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.

Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.

Input

First line contains three integers nk and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers.

Second line contains n integers a1, a2, …, an (0 ≤ ai ≤ 109) — the numbers in the multiset.

Output

If it is not possible to select k numbers in the desired way, output «No» (without the quotes).

Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, …, bk — the selected numbers. If there are multiple possible solutions, print any of them.

Examples
input
3 2 3
1 8 4

output
Yes
1 4

input
3 3 3
1 8 4

output
No

input
4 3 5
2 7 7 7

output
Yes
2 7 7

这个题就是n个数中选%m等于一个数>=k的集合,我忘break了,这fst我服

#include <bits/stdc++.h>
using namespace std;
const int N=100005;
vector<int>V[N];
int main()
{
    int n,k,m;
    scanf("%d%d%d",&n,&k,&m);
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        V[x%m].push_back(x);
    }
    int f=1;
    for(int i=0;i<m;i++)
    {
        int l=V[i].size();
        if(l>=k)
        {
            printf("Yes\n");
            f=0;
            for(int j=0;j<k;j++)
                printf("%d ",V[i][j]);
            break;
        }
    }
    if(f)printf("No");
    return 0;
}

C. Classroom Watch
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer x was given. The task was to add x to the sum of the digits of the number x written in decimal numeral system.

Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.

Input

The first line contains integer n (1 ≤ n ≤ 109).

Output

In the first line print one integer k — number of different values of x satisfying the condition.

In next k lines print these values in ascending order.

Examples
input
21

output
1
15

input
20

output
0

Note

In the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.

In the second test case there are no such x.

 

直接暴力,看见这个题就秒了

#include <bits/stdc++.h>
using namespace std;
vector<int>V;
int main()
{
    int n;
    cin>>n;
    int t=0,c=n;
    while(c)
    {
       c/=10;
       t++;
    }
    for(int i=n-t*10;i<=n;i++)
    {
        int s=i,b=i;
        while(b)
        {
            s+=b%10;
            b/=10;
        }
        if(s==n)V.push_back(i);
    }
    printf("%d\n",V.size());
    for(int i=0;i<V.size();i++)
        printf("%d\n",V[i]);
    return 0;
}

D. Sorting the Coins
time limit per test

1 second

memory limit per test

512 megabytes

input

standard input

output

standard output

Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.

For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:

  1. He looks through all the coins from left to right;
  2. If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.

Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.

Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for ntimes. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.

The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.

Input

The first line contains single integer n (1 ≤ n ≤ 300 000) — number of coins that Sasha puts behind Dima.

Second line contains n distinct integers p1, p2, …, pn (1 ≤ pi ≤ n) — positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p1, then coin located at position p2 and so on. Coins are numbered from left to right.

Output

Print n + 1 numbers a0, a1, …, an, where a0 is a hardness of ordering at the beginning, a1 is a hardness of ordering after the first replacement and so on.

Examples
input
4
1 3 4 2

output
1 2 3 2 1

input
8
6 8 3 4 7 2 1 5

output
1 2 2 3 4 3 4 5 1

Note

Let’s denote as O coin out of circulation, and as X — coin is circulation.

At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won’t make any exchanges.

After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.

XOOO  →  OOOX

After replacement of the third coin, Dima’s actions look this way:

XOXO  →  OXOX  →  OOXX

After replacement of the fourth coin, Dima’s actions look this way:

XOXX  →  OXXX

Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.

00000000xxx0000xxxx删掉最后一段连续x之后剩下x的个数+1

#include <bits/stdc++.h>
using namespace std;
const int N=300005;
int p[N];
int vis[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&p[i]);
    int f=0,pos=n;
    memset(vis,0,sizeof(vis));
    putchar('1');
    int ans=0;
    for(int i=0;i<n;i++){
        vis[p[i]]++;
        while(vis[pos]==1){
            f++;
            pos--;
        }
        ans=i-f+2;
        printf(" %d",ans);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/BobHuang/p/7679886.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/108103.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 伊甸园_绿田园农业

    伊甸园_绿田园农业近日,经国务院批复,《全国高标准农田建设规划(2021-2030年)》(以下简称《规划》)正式印发实施。《规划》指出,到2035年,通过持续改造提升,全国高标准农田保有量和质量进一步提高,绿色农田、数字农田建设模式进一步普及,支撑粮食生产和重要农产品供给能力进一步提升,形成更高层次、更有效率、更可持续的国家粮食安全保障基础。《规划》要求利用数字技术,推动农田建设、生产、管护相融合,提高全要素生产效率。重点推进物联网、大数据、移动互联网、智能控制、卫星定位等信息技术在农田建设中的应用,配套耕地质量综合监测点

    2022年10月21日
    2
  • 进销存ERP源码 进销存APP源码 带小程序ERP源码

    进销存ERP源码 进销存APP源码 带小程序ERP源码前端开发:uniapp后端开发:PHP数据库:MySql移动端:APP+小程序界面简洁,前端采用Bootstrap以及Bootstrap-table相结合,实现自适应的效果、弹窗等。

    2022年5月31日
    69
  • 互联网研发部门组织架构_百度组织架构图2019

    互联网研发部门组织架构_百度组织架构图2019互联网业务研发架构体系指南(草稿V0.0.1)大纲业务技术 稳定性 【稳定性day0】稳定性治理的三种思想—亚马逊、Netflix与蚂蚁金服 【稳定性day1】从DBA到运维架构总监之路-专注的力量 【稳定性day2】当当网的高可用之道 【稳定性day3】蘑菇街的运维体系-如何撑住双十一 【稳定性day4】美团外卖高可用的演进之路-日活两千万的…

    2022年10月12日
    3
  • 新手组装矿机_BTD挖矿

    新手组装矿机_BTD挖矿离上次发挖矿的教程已经过去两个多月了。这两个多月发生了什么事情呢?特斯拉买入15亿美刀BTC美图也不修图买BTC和ETH去了美国一大波ETF申请中加密币交易所coinbase快要上市了20多万一枚的比特币冲到了40万2100一张的二手1660s涨到4000多了…..这段时间我也没有闲着,断断续续收了十几张卡,装了三台矿机。趁着第一波投入已经回本的好心情,给大家分享一下装显卡矿机的经验。(不做投资建议,不送显卡,要不要高位站岗完全看你们自己!)我本来是没时间来.

    2022年9月30日
    3
  • loadworkbook Python_load with

    loadworkbook Python_load withPython——load_workbook用法功能方法示例文件模块读取功能读取excel文件,并进行操作方法示例文件模块读取fromopenpyxlimportload_workbookwb=load_workbook(“电信成绩单.xlsx”)wb'<openpyxl.workbook.workbook.Workbookat0x1ad7ad45ac8>’ws=wb.activews<Worksheet”电子信息2班”>…

    2025年6月18日
    2
  • 2个list取交集_角的集合如何取交集

    2个list取交集_角的集合如何取交集两个List集合取交集、并集、差集、去重并集的一个简单Demo,可供参考:importjava.util.ArrayList;importjava.util.List;importstaticjava.util.stream.Collectors.toList;publicclassTest{publicstaticvoidmain(String[]args){List<String>list1=newArrayLi

    2022年10月6日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号