Codeforces Round #719 (Div. 3) A B C D题

A.题
双指针模拟

/*@author:ntttttt
to->myself->add oil!*/
#include<bits/stdc++.h>
using namespace std;
#define gcd __gcd
#define _orz ios::sync_with_stdio(false)
#define fi first
#define se second
#define lc i<<1
#define rc i<<1|1
#define sf scanf
#define pf printf
#define mem(str,num) memset(str,num,sizeof(str))
#define lowbit(a) ((a)&(-a))
typedef long long ll;
typedef pair<int,int> pll;
typedef pair<ll,ll> pLL;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9+7;
const int N = 1e6+10;
ll qpow(ll a, ll b){ll res = 1; while(b){if(b&1)res = a*res%mod;b >>= 1;a=a*a%mod;}return res;}
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int st[100] = {0};
        int n;
        cin >> n;
        string s;
        cin >> s;
        int f = 0;
        for(int i = 0; i < n; i++){
            int j = i;
            if(st[s[j]]){
                f = 1;
                break;
            }
            while(s[j] == s[i] && j < n) j++; 
            st[s[i]] = 1;
            i = j;
            i--;                   
        }

        if(f) cout <<"NO"<<endl;
        else{
            cout <<"YES"<< endl;
        }
    }
    return 0;
}

B.题

/*@author:ntttttt
to->myself->add oil!*/
#include<bits/stdc++.h>
using namespace std;
#define gcd __gcd
#define _orz ios::sync_with_stdio(false)
#define fi first
#define se second
#define lc i<<1
#define rc i<<1|1
#define sf scanf
#define pf printf
#define mem(str,num) memset(str,num,sizeof(str))
#define lowbit(a) ((a)&(-a))
typedef long long ll;
typedef pair<int,int> pll;
typedef pair<ll,ll> pLL;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9+7;
const int N = 1e6+10;
ll qpow(ll a, ll b){ll res = 1; while(b){if(b&1)res = a*res%mod;b >>= 1;a=a*a%mod;}return res;}
int main()
{
    int t;
    cin >> t;
    while(t--){
        int n;
        ll res = 0;
        cin >> n;
        if(n < 10) cout << n << endl;
        else{
            int q = n;
            int cnt = 0;
            while(q){
                int t = q%10;
                cnt++;
                q /= 10;        
            }
            res += 9*(cnt-1);
            ll num = 0;
            for(int i = cnt-1; i >= 0; i--){
                num += pow(10.0,i);
            }
            //cout << num << endl;
            int f = 0;
            for(int i = 1; i <= 9;i++){
                if(n < num*i) break;
                f = i; 
            }
            res += f;
            cout << res << endl;
        }
    }
    return 0;
}

C题:

/*@author:ntttttt
to->myself->add oil!*/
#include<bits/stdc++.h>
using namespace std;
#define gcd __gcd
#define _orz ios::sync_with_stdio(false)
#define fi first
#define se second
#define lc i<<1
#define rc i<<1|1
#define sf scanf
#define pf printf
#define mem(str,num) memset(str,num,sizeof(str))
#define lowbit(a) ((a)&(-a))
typedef long long ll;
typedef pair<int,int> pll;
typedef pair<ll,ll> pLL;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9+7;
const int N = 1e6+10;
ll qpow(ll a, ll b){ll res = 1; while(b){if(b&1)res = a*res%mod;b >>= 1;a=a*a%mod;}return res;}
int e[101][101];
int main()
{

    int t;
    cin >> t;
    while(t--){
        mem(e,0);
        int n;
        cin >> n;
        int cnt = 0;
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                e[i][j] = ++cnt;  

        if(n == 1) cout << 1 << endl;
        else if(n == 2) cout << -1 << endl;
        else{
            for(int i = 0; i < n; i++)
                for(int j = 0; j < n; j++){
                    if(j%2){
                        int t = (j+1)%n;
                        swap(e[i][j],e[t][j]);
                       // e[i][j] = e[t][j];
                    }
                }

            for(int i = 0; i < n ;i++){
                for(int j = 0; j < n; j++){
                    cout << e[i][j]<<" ";
                }
                cout << endl;                          
            }
  
        }                  
    }
    return 0;
}

D.
注意开long long
因为没开long long test five 就wa了

/*@author:ntttttt
to->myself->add oil!*/
#include<bits/stdc++.h>
using namespace std;
#define gcd __gcd
#define _orz ios::sync_with_stdio(false)
#define fi first
#define se second
#define lc i<<1
#define rc i<<1|1
#define sf scanf
#define pf printf
#define mem(str,num) memset(str,num,sizeof(str))
#define lowbit(a) ((a)&(-a))
typedef long long ll;
typedef pair<int,int> pll;
typedef pair<ll,ll> pLL;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9+7;
const int N = 2e5+10;
ll qpow(ll a, ll b){ll res = 1; while(b){if(b&1)res = a*res%mod;b >>= 1;a=a*a%mod;}return res;}
int a[N];
int b[N];
map<ll,ll> cnt;
int main()
{
    int t;
    cin >> t;
    while(t--){
        
        cnt.clear();
        int n;
        cin >> n;
        for(int i = 1; i <= n; i++){
            cin >> a[i];
            b[i] = a[i] - i;
            cnt[b[i]] ++;
        }
        ll res = 0;
        for(auto i:cnt){
            res += i.second*(i.second-1)/2;
        }
        cout << res << endl;   
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值