PAT (Advanced) 1046. Shortest Distance (20)
来源:互联网 发布:苹果越狱音乐软件 编辑:程序博客网 时间:2024/05/22 13:37
#include <iostream>#include <vector>using namespace std;int main(){int n;cin >> n;int tot = 0;vector<int> dis(n+1);dis[0] = 0;int tmp;for (int i = 1; i <= n; i++){cin >> tmp;dis[i] = dis[i - 1] + tmp;tot += tmp;}int m;cin >> m;int begin, end;int sum;for (int i = 0; i < m; i++){sum = 0;cin >> begin >> end;sum = abs(dis[begin - 1] - dis[end - 1]);if (sum << 1 < tot)cout << sum << endl;elsecout << tot - sum << endl;}return 0;}
0 0
- PAT (Advanced) 1046. Shortest Distance (20)
- 【PAT】【Advanced Level】1046. Shortest Distance (20)
- 【C++】PAT(advanced level)1046. Shortest Distance (20)
- 【PAT】1046.Shortest Distance (20)
- 【PAT】1046. Shortest Distance (20)
- PAT 1046. Shortest Distance (20)
- PAT 1046. Shortest Distance (20)
- PAT 1046. Shortest Distance (20)
- pat 1046. Shortest Distance (20)
- PAT 1046. Shortest Distance (20)
- 【PAT】1046. Shortest Distance (20)
- PAT 1046. Shortest Distance (20)
- PAT (Advanced Level) Practise 1046 Shortest Distance (20)
- PAT (Advanced Level) Practise 1046 Shortest Distance (20)
- PAT (Advanced Level) 1046. Shortest Distance (20) 求环中两点之间的距离
- 1046. Shortest Distance (20)【贪心】——PAT (Advanced Level) Practise
- Pat(Advanced Level)Practice--1046(Shortest Distance)
- PAT 1046. Shortest Distance
- 利用BeanUtils在对象间复制属性
- TCP/IP协议基础(总结)
- c++ 队列基本操作实现
- web前端设计
- Hibernate实战_笔记5(Hibernate、EJB3、JPA)
- PAT (Advanced) 1046. Shortest Distance (20)
- 13计算机毕业设计
- 九度题目1014:排名 && 2005年浙江大学计算机及软件工程研究生机试真题
- Codeforces Round #234 (Div. 2)
- [转载]windows路径操作API函数
- DirectX10一变换(三)
- Unity3d +vs2012 多线程.多并发网络解决方案(C#)
- 达内学习的java类库01
- LAMP服务器性能优化技巧之加速PHP【篇三】