【BestCoder】 HDOJ 5163 Taking Bus
来源:互联网 发布:多益网络绑定战盟 编辑:程序博客网 时间:2024/04/30 07:04
分类讨论一下就行啦。。。。
#include <iostream>#include <queue> #include <stack> #include <map> #include <set> #include <bitset> #include <cstdio> #include <algorithm> #include <cstring> #include <climits>#include <cstdlib>#include <cmath>#include <time.h>#define maxn 200005#define maxm 400005#define eps 1e-10#define mod 1000000007#define INF 0xi3f3f3f3f#define PI (acos(-1.0))#define lowbit(x) (x&(-x))#define mp make_pair#define ls o<<1#define rs o<<1 | 1#define lson o<<1, L, mid #define rson o<<1 | 1, mid+1, R#define pii pair<int, int>//#pragma comment(linker, "/STACK:16777216")typedef long long LL;typedef unsigned long long ULL;//typedef int LL;using namespace std;LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}// headint n, m;LL sum[maxn];void read(){ scanf("%d%d", &n, &m), n--; for(int i = 1; i <= n; i++) { scanf("%I64d", &sum[i]); } for(int i = n+1; i <= 2 * n; i++) sum[i] = sum[2 * n - i + 1]; for(int i = 1; i <= 2 * n; i++) sum[i] += sum[i-1]; //for(int i = 1; i <= 2 * n; i++) printf("AAA %d\n", sum[i]);}LL calc(int a, int b, int d){ if(a == b) return 0; //printf("AAA %d %d %d\n", a, b, sum[6]); if(d == 0) { if(a < b) return sum[b-1] - sum[a-1]; else { b = 2 * n - b + 1; return sum[b] - sum[a-1]; } } else { if(a > b) return sum[a-1] - sum[b-1]; else return sum[b-1] + sum[a-1]; }}void work(){ int now = 1, a, b, t = n + 1; while(m--) { int d = 0; scanf("%d%d", &a, &b); LL ans; ans = calc(now, a, d); if(a < now) d = 1; ans += calc(a, b, d); now++; if(now > t) now -= t; if(a == b) printf("0\n"); else printf("%I64d\n", ans); }}int main(void){ int _; while(scanf("%d", &_)!=EOF) { while(_--) { read(); work(); } } return 0;}
0 0
- 【BestCoder】 HDOJ 5163 Taking Bus
- hdu 5163 Taking Bus (BestCoder Round #27)
- bestcoder 1002 Taking Bus
- HDU 5163 Taking Bus
- HDU 5163 Taking Bus
- HDU 5163 Taking Bus
- hdu 5163 Taking Bus 水题
- hdu 5163 Taking Bus(模拟)
- 杭电 hdu 5163 Taking Bus【模拟】
- hdu 5163 Taking Bus(模拟)
- hdu5163---Taking Bus
- 【CUGBACM15级BC第27场 B】hdu 5163 Taking Bus
- Bestcoder_Round#27_1002-Taking bus(HDUOJ_5163)
- hdoj 3420 bus Fair
- hdoj 1690 Bus System
- HDOJ 5973 Game of Taking Stones
- 【BestCoder】 HDOJ 5088
- 【BestCoder】 HDOJ 5101 Select
- 最受欢迎的文本编辑器推荐之NOTEPAD++..【Pnoter】
- Android LayoutInflater详解
- linux设备驱动程序总述
- 将字符串中的(汉字Unicode编码)解析成汉字
- 【BestCoder】 HDOJ 5162 Jump and Jump...
- 【BestCoder】 HDOJ 5163 Taking Bus
- 内核设备模型分析
- 发送带附件的邮件 java
- 【AC自动机】 HDOJ 5164 Matching on Arrayy
- 不止是产品经理(一)----作为刚入行产品经理,如何开展工作?
- 黑马程序员--线程
- USACO 2.1 The Castle
- 设计模式一:单例模式
- Android ADB命令大全(通过ADB命令查看wifi密码、MAC地址、设备信息、操作文件、查看文件、日志信息、卸载、启动和安装APK等)