Codeforces Round #677 (Div. 3)-- A--E的题解

A. Boring Apartments

#include<bits/stdc++.h>
using namespace std;
#define IOS                    \
  ios::sync_with_stdio(false); \
  cin.tie(0);                  \
  cout.tie(0)
#define lowbit(a) (a & (-a))
#define ll long long
const ll llinf = 0x3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int N=2e5+10;
const int maxn = 1e5 + 10;
const int minn = 1e9 + 10;
const double PI = acos(-1.0);
#define mod 998244353
ll pow(ll a, ll b, ll m)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1)
            ans = ans * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return ans;
}

/*------------------------------------------------------*/

int gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int a[maxn],ans;
int solve(int x)
{
    ans=0;
    while(x)
    {
        ans++;
        x/=10;
    }
    return ans;
}
int main()
{
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int u=n%10;
        int s=(u-1)*10;
        if(s<0)
            s=0;
        int w=solve(n);
        for(int i=1;i<=w;i++)
        {
            s+=i;
        }
        cout<<s<<endl;

    }
    return 0;
}

B. Yet Another Bookshelf

#include <iostream>
#include<algorithm>
using namespace std;
int a[15000];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i=0;i<n;i++)
        cin>>a[i];
        int s=0,w=0,cnt=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]==1)
            {
                cnt++;
            }
            else if(cnt&&a[i]==0)
            {
                s++;
            }
            if(a[i]==1&&cnt==2)
            {
                w+=s;
                s=0;
                cnt=1;
            }
        }
        cout<<w<<endl;
    }
    return 0;
}

C. Dominant Piranha

#include <iostream>
#include<algorithm>
#include<map>
#include<set>
#define ll long long
using namespace std;
int a[350000];
set<int>tp;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        for(int i=1; i<=n+10; i++)
        {
            a[i]=0;
        }
        tp.clear();
        int maxx=0;
        int u;
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
            if(maxx<=a[i]){
                maxx=a[i];
                u=i;
            }
            tp.insert(a[i]);
        }
        if(tp.size()<=1)
        {
            printf("-1\n");
        }
        else
        {
            int w=0,s=0,cnt=0;
            for(int i=1;i<=n; i++)
            {
                if(a[i]!=maxx&&!cnt)
                {
                    s++;
                }
                else if(s&&a[i]==maxx)
                {
                    if(w<s)
                    {
                        w=s;
                        u=i;
                    }
                    s=0;
                }
                if(a[i]==maxx)
                {
                    cnt++;
                }
                else if(cnt&&a[i]!=maxx)
                {
                    s++;
                }
                if(a[i]==maxx&&cnt==2)
                {
                    if(w<s)
                    {
                        w=s;
                        u=i;
                    }
                    s=0;
                    cnt=1;
                }
            }
            printf("%d\n",u);
        }
    }
    return 0;
}

D. Districts Connection
题意:

解题思路:

#include <iostream>
#include<algorithm>
#include<map>
#include<set>
#define ll long long
using namespace std;
int a[100000];
int vis[100000];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        for(int i=1; i<=n+10; i++)
        {
            vis[i]=0;
        }
        int w=0;
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
            if(i!=1&&a[i]!=a[1])
            {
                w=1;
                vis[i]=1;
            }
        }
        if(w==0)
        {
            cout<<"NO"<<endl;
        }
        else
        {
            cout<<"YES"<<endl;
            int pos;
            for(int i=1; i<=n; i++)
            {
                if(vis[i])
                {
                    pos=i;
                    cout<<"1"<<" "<<i<<endl;
                }
            }
            for(int i=1; i<=n; i++)
            {
                if(!vis[i]&&i!=1)
                {
                    cout<<pos<<" "<<i<<endl;
                }
            }
        }
    }
    return 0;
}

F. Zero Remainder Sum添加链接描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值