牛客周赛 57 (ABCDF)

牛客周赛 57 (ABCDF)

A

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ull unsigned long long
typedef long long LL;
typedef pair<int, int> PII;
int dy1[] = {0, -1, -1, -1, 0, 1, 1, 1};
int dx1[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

void solve() {
    for(int i=1; i<=5; i++) {
        int a;
        cin >> a;
        if(a==1) {
            cout << i;
            break;
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T = 1;
    //int T;
    //cin >> T;

    while(T --) {
    solve();
}

    return 0;
}

B

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ull unsigned long long
typedef long long LL;
typedef pair<int, int> PII;
int dy1[] = {0, -1, -1, -1, 0, 1, 1, 1};
int dx1[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

string s;

void solve() {
    int n;
    cin >> n;
    cin >> s;
    vector<PII> eges(n-1);
    for(int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        eges[i] = {a, b};
    }
    int cnt = 0;
    for(auto ege : eges) {
        int u = ege.first-1;
        int v = ege.second-1;
        if(s[u] == s[v]) cnt ++;
    }
    cout << cnt;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T = 1;
    //int T;
    //cin >> T;

    while(T --) {
    solve();
}

    return 0;
}

C

#include <bits/stdc++.h>

using namespace std;

bool isGoodNumber(long long n, long long k) {
    while (n > 0) {
        if (n % k > 1) return false;
        n /= k;
    }
    return true;
}

int main() {
    long long n;
    cin >> n;
    
    long long k1 = 2;
    
    long long k2 = n + 1;
    
    if (k2 > 1000000000000000000LL) {
        cout << "NO" << endl;
        return 0;
    }
    
    if (isGoodNumber(n, k1)) {
        cout << "YES" << endl;
        cout << k1 << " " << k2 << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}

D

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ull unsigned long long
typedef long long LL;
typedef pair<int, int> PII;
int dy1[] = {0, -1, -1, -1, 0, 1, 1, 1};
int dx1[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

const int N = 1e6;
int x[N], y[N];
stack<int> a, b, c;

void solve() {
    int n, k, b1;
    cin >> n >> k >> b1;
    for(int i=1; i<=2*n; i++) cin >> x[i] >> y[i];
    for(int i=1; i<=2*n; i++) {
        if(x[i] * k + b1 > y[i]) a.push(i);
        else if (x[i] * k + b1 == y[i]) b.push(i);
        else c.push(i);
    }
    int aa = a.size(), bb = b.size(), cc = c.size();
    int cnt = 0;
    cnt = min(aa, cc);
    if(aa >= cc) {
        aa -= cc;
        if(aa >= bb) cnt += bb;
        else {
            cnt += (aa + bb) / 2;
        }
    } else {
        cc -= aa;
        if(cc >= bb) cnt += bb;
        else {
            cnt += (cc + bb) / 2;
        }
    }

    cout << cnt << "\n";

    while(!a.empty() && !c.empty()) {
        int t1 = a.top(), t2 = c.top();
        a.pop(), c.pop();
        cout << t1 << " " << t2 << " " << 'Y' << "\n";
    }
    while(!b.empty() && !c.empty()) {
        int t1 = b.top(), t2 = c.top();
        b.pop(), c.pop();
        cout << t1 << " " << t2 << " " << 'Y' << "\n";
    }
    while(!a.empty() && !b.empty()) {
        int t1 = a.top(), t2 = b.top();
        a.pop(), b.pop();
        cout << t1 << " " << t2 << " " << 'Y' << "\n";
    }
    while(!a.empty()) {
        int t1 = a.top();
        a.pop();
        int t2 = a.top();
        a.pop();
        cout << t1 << " " << t2 << " " << 'N' << "\n";
    }
    while(!c.empty()) {
        int t1 = c.top();
        c.pop();
        int t2 = c.top();
        c.pop();
        cout << t1 << " " << t2 << " " << 'N' << "\n";
    }
    while(!b.empty()) {
        int t1 = b.top();
        b.pop();
        int t2 = b.top();
        b.pop();
        cout << t1 << " " << t2 << " " << 'Y' << "\n";
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T = 1;
    //int T;
    //cin >> T;

    while(T --) {
    solve();
}

    return 0;
}

F

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ull unsigned long long
typedef long long LL;
typedef pair<int, int> PII;
int dy1[] = {0, -1, -1, -1, 0, 1, 1, 1};
int dx1[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

const int N = 200010;
int n, m, q;
int arr[N];
struct Node {
    int l, r;
    int v; //区间最大值
}tr[4*N]; 

void pushup(int u) { 
    tr[u].v = min(tr[u<<1].v, tr[u<<1|1].v);
}

void build(int u, int l, int r) { //建树
    tr[u] = {l, r};
    if(l == r) {
        tr[u].v = arr[l];
        return; 
    }
    int mid = l+r>>1;
    build(u<<1, l, mid), build(u<<1|1, mid+1, r);
    pushup(u);
}

int query(int u, int l, int r) {
    if(tr[u].l >=l && tr[u].r <= r) return tr[u].v;
    
    int mid = tr[u].l + tr[u].r >> 1;
    int v = 1e9;
    if(l <= mid) v = query(u<<1, l, r);
    if(r > mid) v = min(v, query(u<<1|1, l, r));

    return v;
}

void modify(int u, int x, int v) {
    if(tr[u].l == x && tr[u].r == x) tr[u].v = v;
    else {
        int mid = tr[u].l + tr[u].r >> 1;
        if(x <= mid) modify(u<<1, x, v);
        else  modify(u<<1|1, x, v);
        pushup(u);
    }
}

int cnt[N];
void solve() {
    cin >> n;
    //int sz = 1;
    for(int i=1; i<=n; i++) {
        cin >> m;
        for(int j=1; j<=m; j++) //cin >> cnt[sz];
        //sz ++;
        cin >> arr[cnt[i-1]+j];
        cnt[i] = cnt[i-1]+m;
    }

    //for(int i=1; i<=12; i++) cout << arr[i] << "\n"; 

    build(1, 1, cnt[n]);
    cin >> q;
    while(q --) {
        int t, zuo, you, x;
        cin >> t;
        if(t == 1) {
            cin >> zuo >> you >> x;
            modify(1, cnt[zuo-1]+you, x);
        }
        else {
            cin >> zuo;
            cout << query(1, 1, cnt[zuo]) << '\n';
        }
    }
    //for(int i=1; i<=12; i++) cout << tr[i].v << "\n"; 
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T = 1;
    //int T;
    //cin >> T;

    while(T --) {
    solve();
}

    return 0;
}
/******************************************
............................................
............................................
............................................
............................................
.............................1ffLf1.........
............................GGGGGGGC........
....................8CCCftCCCCC1;LLG,.......
..................:CC8CCC.CCCCCCii..........
.................CC88CCCC.CCCCCCC...........
................CC88CCCCC .8.:8CCC..........
................888 CCCCC.88888G;;,.........
,................888CC88.888888888,.........
:::...............CCC888.888888888..........
:::::............Gi1tC8f888888C88,..........
:::::::,........111tttfffffLG8888...........
:::::::::,....ii111ttttttfffttG.............
::::::::::::i111tttffffffffffttt............
::::::::::11tttttfff....fffffftt ...........
..:::::::1Lf1tff,..........fffff1...........
....,:::iiftG::::::.........,LLGtL..........
::::::;:i11t:;;;;;;::,,,,,,,,, f1ii,::,,,,,,
::::::::i11t:::::::::::::::::::f111:::::::::
::::::::111:::::::::::::::::::::t111::::::::
:::::::i1if::::::,,,,,,,,,,,,,,:i111::::::,:
,,,,,::,8G,,,,,,,,,,,,,,,,,,,,,,,tL1:,,,,,,,
,,,,,,:LGL;,,,,,,,,,,,,,,,,,,,,,,,CLf,,,,,,,
,,,,,;LGGG,,,,:,,,,,,,,,,,,,,,,,,,LGCG,,,,,,
*******************************************/

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值