2014 ACM/ICPC Asia Regional Shanghai Online

1012

the Sum of Cube

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2407    Accepted Submission(s): 936

Problem Description

A range is given, the begin and the end are both integers. You should sum the cube of all the integers in the range.

Input

The first line of the input is T(1 <= T <= 1000), which stands for the number of test cases you need to solve.
Each case of input is a pair of integer A,B(0 < A <= B <= 10000),representing the range[A,B].

Output

For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then output the answer – sum the cube of all the integers in the range.

Sample Input

2
1 3
2 5

Sample Output

Case #1: 36 Case #2: 224

这个大水题居然wa一次

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5
 6 const int maxn = 105;
 7
 8 int main() {
 9     int t;
10     scanf("%d",&t);
11     for(int kase = 1; kase <= t; kase++) {
12         int a, b;
13         scanf("%d %d",&a, &b);
14         long long sum = 0;
15         for(int i = a; i <= b; i++) {
16             sum += i * i * i;
17         }
18         printf("Case #%d: %I64d\n", kase, sum);
19     }
20     return 0;
21 }

wa的原因是对强制类型转换的不熟悉, 对于第16行i*i*i仍然是个int型但是不能自动转换为long long

所以只要加一个强转就可以了-。-

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5
 6 const int maxn = 1005;
 7
 8 int main() {
 9     int t;
10     int a, b;
11     scanf("%d",&t);
12     for(int kase = 1; kase <= t; kase++) {
13         scanf("%d %d",&a, &b);
14         long long sum = 0;
15         for(int i = a; i <= b; i++) {
16             sum += (long long ) i * i * i;
17         }
18         printf("Case #%d: %I64d\n", kase, sum);
19     }
20     return 0;
21 }

时间: 2024-12-10 11:03:44

2014 ACM/ICPC Asia Regional Shanghai Online的相关文章

hdu5045||2014 ACM/ICPC Asia Regional Shanghai Online【数位dp】

大意:有n道题m个熊孩子,每个熊孩子对于每个题的正确率是已知的,对于每一道题必须有且只有一个熊孩子去做, 并且在任意时刻任意两个熊孩子的做的题数之差都不能大于等于2 比如有5个题三个熊孩子 那么1 2 3 3 1是合法的 但是12231是不合法的 求的是最大期望 分析: 题目已知熊孩子的数目最多是十个那么我们可以将其压缩成2进制(1024) dp[i][j]表示对于前i道题,状态为j的最大概率 那么&运算和|运算就能很好的处理这个问题 对于(1<<n - 1) 要将其清空 代码: 1

HDU 5047 Sawtooth 规律+ C++大数模拟 2014 ACM/ICPC Asia Regional Shanghai Online

题意: 用x个大M 可以把平面分成至多几块. 就是折线切割平面的加强版. 一个简单的递推式 : F(x+1) = 16x+1+F(x) 然后转成通项公式,然后C++ 位压大数模拟 #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; const int mod = 1000

HDU Tree LCA 2014 ACM/ICPC Asia Regional Shanghai Online

题意: 给定n个点的树,m个操作 树有点权和边权 下面n-1行给出树边 下面m行操作 : ● ADD1 u v k: for nodes on the path from u to v, the value of these nodes increase by k. ● ADD2 u v k: for edges on the path from u to v, the value of these edges increase by k. 跑个LCA,然后sum0[i]表示i 的点权,lazy

2014 ACM/ICPC Asia Regional Shanghai Online 1006 Sawtooth

<pre name="code" class="cpp">#include<iostream> #include<string> #include<iomanip> #include<algorithm> #include<cstring> #include<cstdio> using namespace std; #define MAXN 9999 #define MAXSIZE

HDU 5052 Yaoge’s maximum profit 裸树链剖分 2014 ACM/ICPC Asia Regional Shanghai Online

题意: 给定n个点的带点权树. 下面n行给出每个点点权表示每个点买卖鸡腿的价格 下面n-1行给出树边 下面Q个操作 Q行 u, v, val 从u走到v,过程中可以买一个鸡腿,然后到后面卖掉,输出max(0, 最大的收益) 然后给[u,v]路径上点点权+=val 思路: 树链剖分裸题 屌丝题解:点击打开链接 #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include &

2014 ACM/ICPC Asia Regional Guangzhou Online Wang Xifeng&#39;s Little Plot HDU5024

一道好枚举+模拟题目.转换思维视角 这道题是我做的,规模不大N<=100,以为正常DFS搜索,于是傻乎乎的写了起来.各种条件限制模拟过程 但仔细一分析发现对每个点进行全部八个方向的遍历100X100X100^8 .100X100个点,每个点在走的时候8中选择,TLE 于是改为另一个角度: 以符合要求的点为拐弯点,朝两个垂直的方向走,求出最远的距离.这样只要对每个点各个方向的长度知道,组合一下对应的就OK. 避免了每个点深搜. PS:搜索的时候x,y写反了,导致构图出现问题,以后用[dy][dx]

HDU 5014 Number Sequence(2014 ACM/ICPC Asia Regional Xi&#39;an Online) 题解

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5014 Number Sequence Problem Description There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules: ● ai ∈ [0,n] ● ai ≠ aj( i ≠ j ) For sequence a and sequ

hdu 5008(2014 ACM/ICPC Asia Regional Xi&#39;an Online ) Boring String Problem(后缀数组&amp;二分)

Boring String Problem Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 219    Accepted Submission(s): 45 Problem Description In this problem, you are given a string s and q queries. For each que

poj 5024&amp;&amp;&amp;2014 ACM/ICPC Asia Regional Guangzhou Online 1003(预处理)

http://acm.hdu.edu.cn/showproblem.php?pid=5024 分析:预处理每个点在八个方向的射线长度,再枚举八种L形状的路,取最大值. 注意题意是求一条最长路,要么一条直线,要么只有一个90角,即L型.其实直线就是L形的一个方向长度为0. 代码: #include<iostream> #include<map> #include<cstdio> #include<string> #include<cstring>