CodeForces 474B Worms (水题,二分)
Codeforces 二分 水题
2023-09-11 14:17:19 时间
题意:给定 n 堆数,然后有 m 个话询问,问你在哪一堆里。
析:这个题是一个二分题,但是有一个函数,可以代替写二分,lower_bound.
代码如下:
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 1e5 + 5; int a[maxn]; int main(){ int n, m; cin >> n; for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); for(int i = 2; i <= n; ++i) a[i] += a[i-1]; cin >> m; int x; while(m--){ scanf("%d", &x); int t = lower_bound(a, a+n, x) - a; printf("%d\n", t); } return 0; }
相关文章
- CodeForces 337A Puzzles
- CodeForces 489E Hiking (二分+DP)
- CodeForces 670D2 Magic Powder - 2 (二分)
- CodeForces 384E Propagating tree (线段树+dfs)
- CodeForces 359D Pair of Numbers (暴力)
- CodeForces 524C The Art of Dealing with ATM (二分)
- CodeForces 702 A Maximum Increase (贪心,高效算法)
- CodeForces 540B School Marks (贪心)
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
- CodeForces 688A Opponents (水题)
- 【CodeForces 699B】One Bomb
- 【CodeForces 557B】Pasha and Tea
- 【CodeForces 618B】Guess the Permutation
- 【CodeForces 618C】Constellation
- Codeforces 441 B. Valera and Fruits
- codeforces Round #259(div2) D解决报告