码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4572 Bottles Arrangement(找规律,仔细读题)

时间:2014-07-16 22:55:54      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   数据   

题目

 

 

bubuko.com,布布扣
//找规律,123321123321123321…发现这样排列恰好可以错开
// 其中注意题中数据范围: M是行,N是列,3 <= N < 2×M
//则猜测:m,m,m-1,m-1,m-2,m-2,……,2,2,1,1求出前m个数字的和就是答案。
//发现案例符合(之前的代码第二天发现案例都跑不对,真不知道我当时眼睛怎么了)


#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>

using namespace std;

int main()
{
    int n, m;
    while( scanf( "%d%d" , &m, &n ) != EOF )
    {
        int ans = 0, id = m, flag = 0;
        for( int i = 0; i < n; i++ )
        {
            ans += id;
            if(flag == 0)
                flag = 1;
            else
                flag = 0,id--;
        }
            printf("%d\n",ans);
    }
    return 0;
}
View Code

 

HDU 4572 Bottles Arrangement(找规律,仔细读题),布布扣,bubuko.com

HDU 4572 Bottles Arrangement(找规律,仔细读题)

标签:style   blog   http   color   os   数据   

原文地址:http://www.cnblogs.com/laiba2004/p/3835462.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!