题目链接
https://www.acwing.com/problem/content/description/1845/
思路因为n的范围很小(只有100),我们枚举每个点作为奶牛的进场点即可,然后因为只能走到下一个牛棚,所以我们只需要循环一次就好啦,单次查找复杂度 O ( N ) O(N) O(N),总复杂度 O ( N 2 ) O(N^2) O(N2)
代码#include
using namespace std;
//----------------自定义部分----------------
#define ll long long
#define mod 1000000007
#define endl "\n"
#define PII pair
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
ll ksm(ll a,ll b) {
ll ans = 1;
for(;b;b>>=1LL) {
if(b & 1) ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
ll lowbit(ll x){return -x & x;}
const int N = 2e6+10;
//----------------自定义部分----------------
int n,m,q,a[N];
int slove(int loc){
int ans = 0;
for(int i = loc,j = 0; j >n;
for(int i = 0;i >a[i];
}
int ans = 0x3f3f3f3f;
for(int i = 0;i
关注
打赏