HDU_5053_2014年鞍山网络赛
来源:互联网 发布:大数据行业是干什么的 编辑:程序博客网 时间:2024/05/17 06:12
我当时怎么不知道有这么水的题。。。
题意:给一个范围[a,b],求区间内整数的立方和。弱弱的再吐槽一下:当时怎么没发现
#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define ll __int64int main(){ ll a, b; int t; scanf("%d", &t); int ans = 1; while(t--) { ll sum = 0, i; scanf("%I64d%I64d", &a, &b); for(i=a; i<=b; ++i) sum += i*i*i; printf("Case #%d: %I64d\n", ans++, sum); } return 0;}
可能是数据太水,用数学公式计算和上面的效率是一样的:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define ll __int64ll get3(ll n){ ll x = n*(n+1)/2; return x * x;}int main(){ ll a, b; int t; scanf("%d", &t); int ans = 1; while(t--) { ll sum = 0, i; scanf("%I64d%I64d", &a, &b); if(!a) a = 1; printf("Case #%d: %I64d\n", ans++, get3(b)-get3(a-1)); } return 0;}
0 0
- HDU_5053_2014年鞍山网络赛
- 2014网络赛 鞍山赛区
- HDU-5001 Walk 2014年鞍山网络赛E题
- hdu5001 鞍山赛区网络赛 E题
- Rotate+hud+2014鞍山网络赛
- 2014 鞍山网络赛 hdu 5003 Osu!
- acm_icpc网络赛第二站:鞍山赛区
- hdu5000 Clone 鞍山网络赛D题
- HDU 4998 Rotate(计算几何)2014年鞍山赛区网络赛
- HDU 4998 Rotate (2014年鞍山赛区网络赛B题)
- HDU 5003 Osu! (2014年鞍山赛区网络赛G题)
- HDU 5000 Clone (2014年鞍山赛区网络赛D题)
- HDU 5001 Walk (2014年鞍山赛区网络赛E题)
- HDU 5006 Resistance (2014年鞍山赛区网络赛J题)
- HDU 5002 Tree (2014年鞍山赛区网络赛F题)
- HDU 5001 Walk(2014年鞍山赛区网络赛E题)
- HDU 5003 Osu!(鞍山网络赛G题)
- HDU 4998 Rotate(鞍山网络赛B题)
- maven项目添加jar包
- js中几种实用的跨域方法原理详解
- [BZOJ 2705] SDOI 2012 Longge的问题 · 欧拉函数
- 宏杉SAN存储断电后分区信息丢失及恢复
- C指针+ STM32 理解
- HDU_5053_2014年鞍山网络赛
- linux下抓包实现原理
- 在Spring中用select last_insert_id()时遇到问题
- HDOJ 产生冠军 2094(set)
- SlidingMenu的使用
- ORA-00376:file 142 cannot be read at this time---ORA-01110
- PHP无限极分类
- 分布式事务——【新生入学系统】
- PV操作——软考探究(五)