Codeforces Round #719 (Div. 3)(a,b,c)

37 篇文章 1 订阅

题目https://codeforc.es/contest/1520

简单题

a

一个字符串,出现在一个地方的字符,不能再第二个地方出现

A A A A Z A A A A A AAAAZAAAAA AAAAZAAAAA -------NO
F F G Z Z Z Y FFGZZZY FFGZZZY ------------- YES

#include<bits/stdc++.h>
#define ll long long 
using namespace std;

const int N = 1e4;

int u[N+10], s[N+10];

void solve()
{
    int n; cin >> n; 
    string str; cin >> str;
    if (n == 1) puts("YES"),return;
    
    char ch;
    for (int i = 0; i < n; i++)
    {
        if (str[i] != str[i+1]) 
        {
            ch = str[i]; // find the first different index
            for (int j = i+1; j < n; j++) 
            {
            	if (str[i] == str[j]) puts("NO"), return;
            }
        }
    }
    puts("YES");
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int T; cin >> T;
    while (T--) 
        solve();
    return 0;
}
 

b

1到n共有多少位数都相同的数

位数相同的数 1 2 3…9, 11, 22…111…11111…

暴力,肯定是不行的
虽然是div3,否则还不如给大家布置c++课后作业?

#include<bits/stdc++.h>
#define ll long long
using namespace std;

ll fun (int a, int b)
{
	ll ans = 0;
	int cnt = 1;
	for (int i = 1; i <= a; ++i){
		ans += cnt * b;
		cnt *= 10;
	}
	return ans;
}

void solve()
{
    ll n, ans = 0; cin >> n;
    for (int i = 1; i <= 9; ++i) 
    	for (int j = 1; j <= 9; ++j) 
    		if (fun(i , j) <= n) ans++;
    		
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int T; cin >> T;
    while (T--)
        solve();
    return 0;
}

或者可以打表

int paiduan(int n)
{
    int count=0;
    if(n<10)return n;
    else if(n<=100)
    {
        n=n/11;
        return 9+n;
    }
    else if(n<=1000)
    {
        n=n/111;
        return 18+n;
    }
    else if(n<=10000)
    {
        n=n/1111;
        return 27+n;
    }
    else if(n<=100000)
    {
        n=n/11111;
        return 36+n;
    }
    else if(n<=1000000)
    {
        n=n/111111;
        return 45+n;
    }
    else if(n<=10000000)
    {
        n=n/1111111;
        return 54+n;
    }
    else if(n<=100000000)
    {
        n=n/11111111;
        return 63+n;
    }
    else
    {
        n=n/111111111;
        return 72+n;
    }
}

c

输入一个数n
上下左右四个值相差大于1

#include<bits/stdc++.h>
using namespace std;

void solve()
{
    int n; cin >> n;
    if (n == 2) {
        cout << "-1\n";
    } else {
        for (int i = 1; i <= n * n; i += 2) {
             cout << i << ' ';
             if ((i + 1) % n == 0) cout << endl;
        }
        for (int i = 2; i <= n * n; i += 2) {
             cout << i << ' ';
             if ((i + 1) % n == 0) cout << endl;
        }
           
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int T; cin >> T;
    while (T--)
        solve();
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值