把握今天,才能拥有明天!
神级烧脑!我用数组做总不对!!!看了大神写的改用vector就对了,谁能告诉我发生了什么?(PS:看别人代码是不对的,除非我真的做不到)
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
int main() {int n;scanf("%d", &n);vector<int> dis(n + 1);int sum = 0, left, right, cnt;for(int i = 1; i <= n; i++) {int temp;scanf("%d", &temp);sum += temp;dis[i] = sum;}scanf("%d", &cnt);for(int i = 0; i < cnt; i++) {scanf("%d %d", &left, &right);if(left > right)swap(left, right);int temp = dis[right - 1] - dis[left - 1];printf("%d\n", min(temp, sum - temp));}return 0;
}
又看了一下,果然是自己想错了,数组和vector没啥区别,自己的思路不对,当然错了······