Codeforces Round #719 (Div. 3) ABCDEF题解


A - Do Not Be Distracted!

题目链接
题意:一个字母只能在一堆出现,后面不能出现

样例没过就交

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int N = 105;
ll t, n, m, x, a[N], sum[N], cnt, q, maxx;
string s;
int main() {
    cin>>t;
    while(t--) {
        cin>>n>>s;
        memset(a, 0, sizeof a);
        q=0;
        a[s[0]-'A']++;//第一个字母忘记存了
        for(int i=1; i<n; i++) {
            if(s[i]!=s[i-1]&&a[s[i]-'A']) {
                q++;
                break;
            }
            a[s[i]-'A']++;
        }
        if(q) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

B - Ordinary Numbers

tmlj
题意 找 1 − n 1-n 1n范围内 数字每位相同的数有几个

WA2后来暴力做了
然后这份代码我偷的 因为比我的好看hhh

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    int vis[50];
    set<long long>se;
    int main()
    {
        for(int i=1;i<=9;i++)
        {
            long long temp=i;
            while(temp<=1000000000)
            {
                se.insert(temp);
                temp=temp*10+i;
    //            cout<<temp<<endl;
            }
        }
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int n,cnt=0;
            scanf("%d",&n);
            for(auto x:se)
            {
                if(x<=n)cnt++;
            }
            printf("%d\n",cnt);
        }
     
        return 0;
    }

C - Not Adjacent Matrix

题目链接
题意:构造 n ∗ n n*n nn的矩阵使 ( i , j ) (i, j) (i,j) ( i , j + 1 ) (i, j+1) (i,j+1) ( i + 1 , j ) (i+1, j) (i+1,j) ( i + 1 , j + 1 ) (i+1, j+1) (i+1,j+1)这几个位置的数字相差不能为1

就想到相差2,然后先排奇数再排偶数

#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
const int N = 1000005;
ll t, n, m, flag, q, dis, a[20], vis[N], ans[20];
int main() {
    cin>>t;
    while(t--) {
        cin>>n;
        q=1;
        m=2;
        if(n==2) {//就2不行
                cout<<-1<<endl;
                continue;
        }
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=n; j++) {
               if(q<=n*n) cout<<q<<" ", q+=2;
               else cout<<m<<" ", m+=2;
            }
            cout<<endl;
        }
    }
    return 0;
}

D - Same Differences

题目链接

题意:给你一串数组,问你有几个 a j − a i = = j − i ( j > i ) aj-ai==j-i(j>i) ajai==ji(j>i)

写的时候被B搞烦了 愣了好久
就是假如满足题目的要求的话 a j − j , a i − i aj-j, ai-i ajj,aii是相等的 就移项呗

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int N = 105;
map<ll, ll> mp;
set<ll> se;
ll t, n, m, x, a[N], sum[N], cnt, q, maxx, ans;
string s;
int main() {
    cin>>t;
    while(t--) {
        cin>>n;
        se.clear();
        mp.clear();
        ans=0;
        for(int i=1; i<=n; i++) {
            cin>>a[i];
            mp[a[i]-i]++;
            se.insert(a[i]-i);
        }
        for(auto x:se) {
            ans+=mp[x]*(mp[x]-1)/2;//就求和公式
        }
        cout<<ans<<endl;
    }
    return 0;
}

E - Arranging The Sheep

题目链接
题意:给你 ∗ . ∗ . . . ∗ . ∗ ∗ 。 *.*...*.**。 .....$"*是小绵羊你要把小绵羊弄到一块去问你最少移多少步

这题超级气的 反正就是加加减减一直能不出来 然后最后一分钟交 然后评测机炸了 然后97%98%99%像等死刑一样 最后re5 干的漂亮

就是中位数啦
建议移步->货仓选址
然后还有 思怡mm(点击即可关注 提供的另外一种思路 动空格的位置 不动羊的 然后空格的位置往羊少的地方放 好棒!!只需2min

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;//就是这里re!!竟然还有人想hack我都这么惨了就因为没关同步
typedef long long ll;
map<ll,int> mp;
ll a[N], b[N], n, t, cnt, m,ans;
string s;
int main(){
	cin>>t;
	while(t--) {
        cin>>n>>s;
        ans=cnt=0;
        for(int i=0; i<n; i++) {
            if(s[i]=='*') a[cnt++]=i+1;
        }
        m=a[cnt/2];
        //cout<<m<<endl;
        for(int i=0; i<cnt; i++) {
            if(a[i]<m) ans+=m-(cnt/2-i)-a[i];
            else if(a[i]>m)ans+=a[i]-(i-cnt/2)-m;//这个地方要搞晕了
        }
        cout<<ans<<endl;
	}
	return 0;
}

在这里:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+86;
typedef long long ll;
char a[maxn];int sum[maxn];
int main(){
    ll t;
    cin>>t;
    while(t--){
         ll n;
        cin>>n;
        for(int i=1;i<=n;i++) {
            cin>>a[i];
            if(a[i]=='*'){
                sum[i]=sum[i-1]+1;
            }  
            else {
                sum[i]=sum[i-1];
            }
        }
        ll ans=0;
        for(int i=1;i<=n;i++){
            if(a[i]=='.') {
                ll minn=min(sum[i],sum[n]-sum[i]);
                ans+=minn;
            }
        }
        cout<<ans<<endl;
    }
 return 0;
}

F1 - Guess the K-th Zero (Easy version)

题目链接
反正交互老是都跑掉啦 不会


总结

水题不能wa 样例好好看

本来能上分的 哭哭 下次一定

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值