HDOJ2015 偶数求和
来源:互联网 发布:centos php5.6 lamp 编辑:程序博客网 时间:2024/05/01 03:36
思路:当n<m时,直接输出n个数的和除以m;当n>m时,分两种情况,n%m==0和!=0
#include <iostream>
#include<stdio.h>
using namespace std;
int main()
{
int n,m;
int sum,ans;
while(cin>>n>>m)
{
sum=0;
ans=0;
if(n<=m)
{
for(int i=1; i<=n; i++)
{
sum+=2;
ans+=sum;
}
printf("%d\n",ans/n);
}
else
{
int count=0;
for(int i=1; i<=n; i++)
{
sum+=2;
ans+=sum;
count++;
if(m==count)
{
if(i!=n)
{
printf("%d ",ans/m);
count=0;
ans=0;
}
else
printf("%d\n",ans/m);
}
if(i==n&&(n%m)!=0)
printf("%d\n",ans/(n%m));
}
}
}
return 0;
}
- HDOJ2015 偶数求和
- HDOJ2015 偶数求和
- HDOJ2015 偶数求和
- hdoj2015(java)偶数求和 (找规律,总结)常看
- HDOJ2015
- hdoj2015
- HDOJ2015
- HDOJ2015
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 数据库约束(1)学习
- 如何实现一个文件系统(五)
- C语言printf打印信息不阻塞显示
- Spring Tool Suite插件
- linux基础之Shell Script入门介绍
- HDOJ2015 偶数求和
- 2011斯坦福大学iOS应用开发教程学习笔记(第一课)MVC.and.Introduction.to.Objective-C
- 看懂SqlServer查询计划
- 网站建设与SEO--1,网站建设的初始准备
- 练习赛5.昆虫繁殖
- perror实现分析(2.0: 具体实现)
- 如何实现一个文件系统(六)
- shell中case的用法学习笔记
- hdu1215七夕节 筛素数+素因子分解+乘法公式