CodeForces #799 训练记录day2

 

A

```

 

#include <bits/stdc++.h>
using namespace std;
const int N =20;
const int mod =11451419;
#define endl '\n'
#define Endl '\n'
#define inf 1e18
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
signed main(){
    int t;cin>>t;
    while(t--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int cnt = 0;
        if (b > a)cnt++;
        if (c > a)cnt++;
        if (d > a)cnt++;
        cout << cnt << endl;
    }
    return 0^0;
}

```

B

真的艹了b题能做17分钟一直在想去重 发现根本不会迭代器

```

#include <bits/stdc++.h>
using namespace std;
const int N =55;
const int mod =11451419;
#define endl '\n'
#define Endl '\n'
#define inf 1e18
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
signed main(){
    int t;cin>>t;
    while(t--) {
        int n;cin>>n;
        set<int>v;
        for(int i=0;i<n;i++){
            int s;cin>>s;
            v.insert(s);
        }
        if((n-v.size())%2)cout<<v.size()-1<<endl;
        else cout<<v.size()<<endl;
    }
    return 0^0;
}

```

C

```

#include <bits/stdc++.h>
using namespace std;
const int N =55;
const int mod =11451419;
#define endl '\n'
#define Endl '\n'
#define inf 1e18
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
signed main(){
    int t;cin>>t;
    while(t--) {
        char s[10][10];
        for(int i=1;i<=8;i++){
            for(int j=1;j<=8;j++){
                cin>>s[i][j];
            }
        }
        int flag=0;
        for(int i=1;i<=8;i++){
            int cnt=0;
            for(int j=1;j<=8;j++){
                if(s[i][j]=='#')cnt++;
            }
            if(cnt==2)flag=1;
            if(flag&&cnt==1){
                for(int j=1;j<=8;j++){
                    if(s[i][j]=='#'){
                        cout<<i<<' '<<j<<endl;
                        goto out;
                    }
                }
            }
        }
        out:1;
    }
    return 0^0;
}

```

D

最开始没想到进位 非常nc

```

#include <bits/stdc++.h>
using namespace std;
const int N =55;
const int mod =11451419;
#define endl '\n'
#define Endl '\n'
#define inf 1e18
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int res=0;
string s;
string ans;
void is(){
    string s1;
    s1=s;
    reverse(s1.begin(),s1.end());
    if(s1==s)res++;
}
signed main(){
    int t;cin>>t;
    while(t--) {
        cin>>s;
        res=0;
        ans=s;
        int x;cin>>x;
        int h=x/60;
        int m=x%60;
        int h1 = (s[0] - '0') * 10 + (s[1] - '0') + h;
        int m1 = (s[3] - '0') * 10 + (s[4] - '0') + m;
        if (m1 >= 60)m1 %= 60,h1++;
        s[3] = m1 / 10 + '0';
        s[4] = m1 % 10 + '0';
        if (h1 >= 24)h1 %= 24;
        s[0] = h1 / 10 + '0';
        s[1] = h1 % 10 + '0';
        is();
        while(ans!=s){
            int h1 = (s[0] - '0') * 10 + (s[1] - '0') + h;
            int m1 = (s[3] - '0') * 10 + (s[4] - '0') + m;
            if (m1 >= 60)m1 %= 60,h1++;
            s[3] = m1 / 10 + '0';
            s[4] = m1 % 10 + '0';
            if (h1 >= 24)h1 %= 24;
            s[0] = h1 / 10 + '0';
            s[1] = h1 % 10 + '0';
            is();
        }
        cout<<res<<endl;
    }
    return 0^0;
}

```

E

不知道为啥 最开始的双指针居然写挂了 我恨字符串

```

#include <bits/stdc++.h>
using namespace std;
const int N =2e5+10;
const int mod =11451419;
#define endl '\n'
#define Endl '\n'
#define inf 1e18
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int L[N],R[N],tmp=0;
signed main(){
    int t;cin>>t;
    while(t--) {
        bool a[N];
        int n, s;
        cin >> n >> s;
        int sum = 0,ans=inf;;
        for (int i = 1; i <= n; i++)cin >> a[i], sum += a[i];
        if (sum < s) {
            cout << -1 << endl;
            continue;
        }
        if (sum == s) {
            cout << 0 << endl;
            continue;
        }
        tmp=0;
        memset(L, 0, sizeof L);
        memset(R, 0, sizeof R);
        for (int i = 1; i <= n; i++) {
            if (a[i] == 1) {
                tmp++;
                L[tmp] = i;
            }
        }
            tmp = 0;
            for (int i = n ; i >= 1; i--) {
                if (a[i] == 1) {
                    tmp++;
                    R[tmp] = n - i + 1;
                }
            }
            for (int i = 0; i <= sum - s; i++) ans = min(ans, L[i] + R[sum - s - i]);
            cout << ans << endl;
        }
    return 0^0;
}

```

F

简单题 最开始想到了容斥 非常牛逼

```

#include <bits/stdc++.h>
using namespace std;
const int N =2e5+10;
const int mod =11451419;
#define endl '\n'
#define Endl '\n'
#define inf 1e18
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
signed main(){
    int t;cin>>t;
    while(t--) {
        int n;cin>>n;
        map<int,int>mp;
        for(int i=0;i<n;i++){
            int s;cin>>s;
            mp[s%10]++;
        }
        vector<int>v;
        for(auto i:mp){
            if(i.second>=3){
                int cnt=3;
                while(cnt--)v.push_back(i.first);
            }else{
                while(i.second--)v.push_back(i.first);
            }
        }
        for(int i=0;i<v.size();i++){
            for(int j=i+1;j<v.size();j++){
                for(int k=j+1;k<v.size();k++){
                    if((v[i]+v[j]+v[k])%10==3){
                        cout<<"YES"<<endl;
                        goto out;
                    }
                }
            }
        }
        cout<<"NO"<<endl;
        out:1;
    }
    return 0^0;
}

```

G

简单题 一眼就想到了全部可以*上再比 没啥好说的 div4没做完 感觉可以重开了

```

#include <bits/stdc++.h>
using namespace std;
const int N =2e5+10;
const int mod =11451419;
#define endl '\n'
#define Endl '\n'
#define inf 1e18
#define int long long
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
signed main(){
    int t;cin>>t;
    while(t--) {
        int n,k;cin>>n>>k;
        int a[N];
        bool b[N];
        for(int i=0;i<n;i++)cin>>a[i];
        for (int i = 0; i < n - 1; i++) {
            b[i] = (a[i] < 2 * a[i + 1]);
        }
        int tot = 0;
        for (int i = 0; i < k; i++) {
            tot += b[i];
        }
        int res = 0;
        if (tot == k)res++;
        for (int i = k; i < n - 1; i++) {
            tot += b[i];
            tot -= b[i - k];
            if (tot == k)res++;
        }
        cout << res << endl;
    }
    return 0^0;
}

```

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值