let's start Code

Max and Electrical Panel

Max and Electrical Panel

 Solution 01:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,c;
    cin >> n >>c;
    int lo = 0, hi = n, res = 0;
    while(hi-lo > 1){
        if(res)cout << 2<<endl<<flush;
        int mid = lo + (hi-lo-1)/8+1;
        cout << 1 << " "<<mid<<endl<<flush;
        cin >> res;
        if(res)hi = mid;
        else lo = mid;
    }
    cout << 3 << " "<<hi<<endl<<flush;
    return 0;
}

Solution 02:



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,c;
    cin >> n >>c;
    int lo = 1, hi = n+1, res = 0;
    while(hi-lo > 1){
        if(res)cout << 2<<endl<<flush;
        int mid = lo + (hi-lo)/60;
        cout << 1 << " "<<mid<<endl<<flush;
        cin >> res;
        if(res)hi = mid+1;
        else lo = mid+1;
    }
    cout << 3 << " "<<lo<<endl<<flush;
    return 0;
}

Solution 03:



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<bits/stdc++.h>
using namespace std;

bool solve(int x)
{
    cout << "1 "<<x<<endl<<flush;
    int a;
    cin >> a;
    return a;
}

int main()
{
    int n,c;
    cin >> n >>c;
    int ans = -1, lg = 0, le = -1;
    int range = sqrt(n);
    //cout << range<<endl;
    for(int i = 1; i <= n; i += range){
           // cout << i << endl;
        if(solve(i)){
            ans = i;
            break;
        }
        lg = i;
        le = min(i+range-1, n);
    }
    cout << 2<<endl<<flush;
    for(int i = lg; i <= le; i++){
        if(solve(i)){
            ans = i;
            break;
        }
    }
    cout << 3 << " "<<ans<<endl<<flush;
    return 0;
}

Share:

No comments:

Post a Comment

About

let's start CODE

Popular Posts