zoukankan      html  css  js  c++  java
  • AtCoder 5749 C

    Problem Statement

    Given are three integers N, K, and S.

    Find a sequence A1,A2,…,AN of N integers between 1 and 109 (inclusive) that satisfies the condition below. We can prove that, under the conditions in Constraints, such a sequence always exists.

    • There are exactly K pairs (l,r) of integers such that 1≤lrN and Al+Al+1+[cdots]+Ar=S.

    Constraints

    • 1≤N≤105
    • 0≤KN
    • 1≤S≤109
    • All values in input are integers.

    Input

    Input is given from Standard Input in the following format:

    N K S
    

    Output

    Print a sequence satisfying the condition, in the following format:

    A1 A2  AN
    

    Sample Input 1

    Copy
    4 2 3
    

    Sample Output 1

    Copy
    1 2 3 4
    

    Two pairs (l,r)=(1,2) and (3,3) satisfy the condition in the statement.


    Sample Input 2

    Copy
    5 3 100
    

    Sample Output 2

    Copy
    50 50 50 30 70
    

    思路:看似抽象的问题要简单化思考,许多看似要枚举很多情况的题目其实只要抓住最核心的成立条件即可。

    ps:今天一天把收藏的洛谷改版之前新手村的题目做了,感觉确实都是很简单水题,想想上学期还觉得把新手村的题刷通都已经很不错了 233

    ac代码:

    #include<bits/stdc++.h>
    using namespace std;
    #define rep(i,a,n) 	for(int i=a;i<=n;i++)
    #define per(i,a,n) 	for(int i=n;i>=a;i--)
    #define read(x) 	scanf("%d",&x)
    #define Read(x,y) 	scanf("%d%d",&x,&y)
    #define write(x) 	printf("%d
    ",x)
    #define INF 0x3f3f3f3f
    #define MAX_N 6010
    typedef long long ll;
    
    
    int main()
    {	
    	ll n,s,k;
        cin >> n >> k >> s;
        ll c = s;
        if(s > 1) {
            c --;
        }
        else c ++;
        for(int i = 1;i <= k;++i) cout<<s<<' ';
        for(int i = 1;i <= n - k; ++i) cout<<c<<' ';
    
    	return 0;
    }
    

      

  • 相关阅读:
    Ehcache缓存配置和基本使用
    微信公众号接入图灵机器人实现自动回复消息
    数据库索引的使用
    oracle中=>是什么意思
    [转载]AppSettings和ConnectionStrings的区别
    获得字符串长度
    HTML------8.调用接口 实现动态折现图
    HTML------7.编辑折现图
    JAVA------14.今日和昨日时间转换
    JAVA------13.字符串去掉非数字 ,从大到小排序
  • 原文地址:https://www.cnblogs.com/jaszzz/p/12740746.html
Copyright © 2011-2022 走看看