QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#575118#5513. Advertisement 2ModyKachefCompile Error//C++231.2kb2024-09-19 10:39:182024-09-19 10:39:19

Judging History

你现在查看的是最新测评结果

  • [2024-09-19 10:39:19]
  • 评测
  • [2024-09-19 10:39:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long 

int n;
int x[1001] , e[1001]; 

void brute(int i , int msk , int cnt){
    if (i == n){
        if (msk == (1<<n)-1) ans = min(ans , cnt); 
        return;
    }
    brute(i+1 , msk , cnt);
    int nmsk = msk;
    for (int j = 0 ; j < n;  j++){
        if (abs(x[i]-x[j]) <= e[i]-e[j]) nmsk|=(1<<j); 
    }
    brute(i+1 , nmsk , cnt+1); 
}

bool adj[(int)1001][1001]; 

signed main(){
    cin >> n;
    vector<pair<int , int>> v(1); 
    for (int i = 1 ; i<=  n; i++){
        cin >> x[i] >> e[i]; 
        v.push_back({e[i] , x[i]}); 
    }    
    sort(v.begin()+1 , v.end() , greater<>());
    for (int i = 1 ; i <= n ; i++){
        e[i] = v[i].first;
        x[i] = v[i].second; 
    }
    for (int i = 1 ; i <= n ; i++){
        for (int j = 1 ; j <= n ; j++){
            if (abs(x[i] - x[j]) <= e[i] - e[j]) adj[i][j] = 1;  
        }
    }
    int ans = 0; 
    bool vis[(int)n+1] = {}; 
    for (int i = 1 ; i <= n ; i++){
        if (vis[i]) continue;
        ans++; 
        for (int j = 1 ; j <= n ; j++){
            if (adj[i][j]) vis[j] = 1; 
        }
    }
    cout << ans; 
}

// | X[i] - X[j] | <= E[i]

Details

answer.code: In function ‘void brute(long long int, long long int, long long int)’:
answer.code:10:30: error: ‘ans’ was not declared in this scope; did you mean ‘abs’?
   10 |         if (msk == (1<<n)-1) ans = min(ans , cnt);
      |                              ^~~
      |                              abs