zoukankan      html  css  js  c++  java
  • URAL 1731. Dill(数学啊 )

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1731



    1731. Dill

    Time limit: 0.5 second
    Memory limit: 64 MB
    Ivan Vasil'evich likes to work in his garden. Once he heard that dill was a very beautiful and healthy crop and planted his whole garden with two varieties of it.
    When the dill was ripe, Ivan Vasil'evich harvested it and put it into boxes. He filled n boxes with dill of the first variety and m boxes with dill of the second variety. The weight of each box with dill in kilograms was an integer and all the weights were different. In order to please his neighbors Ivan Ivanovich and Ivan Nikiforovich, Ivan Vasil'evich decided to give each of them two boxes with dill, one box of each variety. Ivan Vasil'evich didn't want Ivan Ivanovich and Ivan Nikiforovich to quarrel, so he decided that the total weight of the boxes given to each of the neighbors should be equal. Ivan Vasil'evich considered all the possible variants and saw that this was impossible. Find the weights of all the boxes with dill stocked by Ivan Vasil'evich.

    Input

    The only input line contains space-separated integers n and m (2 ≤ nm ≤ 50).

    Output

    In the first line output n space-separated integers. These must be the weights of the boxes with the first variety of dill. In the second line output m space-separated integers, which are the weights of the boxes with the second variety of dill. The integers must be positive, different, and should not exceed 109. If there are several solutions, output any of them. If there is no solution, output the line “It is a lie!”.

    Sample

    input output
    2 3
    1 2
    5 10 12


    代码例如以下:

    #include <cstdio>
    #include <cstring>
    #define LL __int64
    int main()
    {
        int n, m;
    
        int c1[57], c2[57];
        while(~scanf("%d%d",&n,&m))
        {
            int a = 1;
            for(int i = 1; i <= n; i++)
            {
                c1[i] = a++;
            }
            c2[1] = a;
            for(int i = 2; i <= m; i++)
            {
                c2[i] = a+c2[i-1];
            }
            printf("%d",c1[1]);
            for(int i = 2; i <= n; i++)
            {
                printf(" %d",c1[i]);
            }
            printf("
    ");
            printf("%d",c2[1]);
            for(int i = 2; i <= m; i++)
            {
                printf(" %d",c2[i]);
            }
            printf("
    ");
        }
        return 0;
    }
    


  • 相关阅读:
    多线程编程:阻塞、并发队列的使用总结
    为什么阿里的程序员那么帅?---原来他们都有"编码规约扫描"神器在手
    多线程编程:多线程并发制单的开发记录【一】
    如何使用线程锁来提高多线程并发效率
    如何在分布式环境中同步solr索引库和缓存信息
    前端性能优化指南
    DOM操作方法、属性
    CSS样式手册
    XSS跨站脚本攻击
    数组和对象的使用方法
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/7246641.html
Copyright © 2011-2022 走看看