hdu 1001

Sum Problem

Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 342001    Accepted Submission(s): 86236

Problem Description

Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).

In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.

Input

The input will consist of a series of integers n, one integer per line.

Output

For
each case, output SUM(n) in one line, followed by a blank line. You may
assume the result will be in the range of 32-bit signed integer.

Sample Input

1
100

Sample Output

1

5050

题意:求1到n的和

#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    while(cin>>a){
        c=0;
        for(b=1;b<=a;b++)
            c+=b;
        cout<<c<<endl<<endl;
    }
    return 0;
}
时间: 2024-12-24 22:47:10

hdu 1001的相关文章

HDU 1001(TLE代码)★留着待修改★

1 #include <stdio.h> 2 #include <math.h> 3 struct node{ 4 double x,y; 5 }point[100000]; 6 struct node nod; 7 int n=0,i=0; 8 int sort(void){ //选择排序:从小到大 9 int j,k; 10 for(i=0;i<n;i++){ 11 nod.x=point[i].x; 12 nod.y=point[i].y; 13 k=i; 14 for

HDU 1001 Sum Problem

Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. InputThe input will consist of a series of integers n, one integer per line. OutputFor each ca

HDU 1001 Sum Problem C/C++

Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Input The input will consist of a series of integers n, one integer per line. Output For each

水题/hdu 1001 Sum Problem

题意 给出一个数n,求1+2+??+n=? 分析 注意多case Accepted Code 1 /* 2 PROBLEM:hdu1001 3 AUTHER:NicoleLam 4 MEMO:水题 5 */ 6 7 #include<cstdio> 8 9 int main() 10 { 11 int n; 12 while (scanf("%d",&n)!=EOF) 13 { 14 int s=0; 15 for (int i=1;i<=n;i++) s+=

ACM HDU 1001

Problem Description Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Sum Problem Input The input will consist of a series of integers n, one integer per line. Outp

HDU1001 关于累加公式的隐性类型转换

HDU 1001就卡了. 受到小白的启发遇到这样的循环题目直接转化成公式求解以优化时间.但是!我就是过不了! 问题代码: #include<stdio.h> int main() { int a; while(scanf("%d",&a)!=EOF) printf("%d\n\n",a*(1+a)/2); return 0; } 问题在于虽然题目中表示最后结果会在32bit内,但是没保证a*(1+a)也是32bit.......菜鸟又忽略了在除法

HDU 4907 (杭电BC#3 1001)Task schedule(水)

题目地址:HDU 4907 水题...不多说..哈希后从后往前遍历一遍就行了. 代码如下: #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queue> #include <map> #include<a

Valentine&#39;s Day Round 1001.Ferries Wheel(hdu 5174)解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5174 题目意思:给出 n 个人坐的缆车值,假设有 k 个缆车,缆车值 A[i] 需要满足:A[i−1]<A[i]<A[i+1](1<i<K).现在要求的是,有多少人满足,(他坐的缆车的值 + 他左边缆车的值) % INT_MAX == 他右边缆车的值. 首先好感谢出题者的样例三,否则真的会坑下不少人.即同一部缆车可以坐多个人.由于缆车的值是唯一的,所以可以通过排序先排出缆车的位置.求出

HDU 4861(多校)1001 Couple doubi

Problem Description DouBiXp has a girlfriend named DouBiNan.One day they felt very boring and decided to play some games. The rule of this game is as following. There are k balls on the desk. Every ball has a value and the value of ith (i=1,2,...,k)