10.8Codeforces Round #747 (Div. 2)

一、Consecutive Sum Riddle

#include<iostream>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--){
        long long n;
        cin >> n;
        cout << -(n - 1) << " " << n << endl;
    }
    return 0;
}

二、Special Numbers

#include <iostream>
using namespace std;
#define _rep(i,a,b) for( int i=(a); i<=(b); ++i)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
const int mod = 1e9 + 7;
int n, k, ans;
signed main() {
    IOS;
    int t;
    cin >> t;
    while (t-- && cin >> n >> k) {
        ans = 0;
        int cnt = 0;
        while (k) {
            int a = 1;
            if (k & 1) {
                _rep(j, 1, cnt) {
                    
                    a = (a * n) % mod;
                }
                ans = (ans + a) % mod;
            }
            k = k >> 1;
            cnt++;
        }
        cout << ans << "\n";
    }
    return 0;
}

三、Make Them Equal

第一种情况:
只有一个字符不同,且该字符是最后一个,输出n-1,不然输出n
第二种情况
在字符串的后半段,如果存在当前位置的字符等于目标字符,
直接输出当前下标位置(记得加一)
如果不存在,就输出n-1和n
其他情况特判。

#include <iostream>
#include <string>
using namespace std;
int t, n, ac;
char tmp;
string s;
void solve() {
	cin >> t;
	while (t-- && cin >> n >> tmp >> s) {
		ac = 0;
		int ans = n;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] != tmp) {
				ac++;
				if (i + 1 == ans) ans--;
			}
		}
		if (ac == 0) {
			cout << ac << "\n";
			continue;
		}
		if (ac == 1) {
			cout << ac << "\n";
			cout << ans << "\n";
			continue;
		}
		ac = 2;
		for (int i = s.size() - 1; i >= 0; i--) {
			if (s[i] != tmp) continue;
			if (i + 1 > (s.size() / 2)) {
				ac = 1;
				ans = i + 1;
				break;
			}
		}
		cout << ac << "\n";
		if (ac == 1) {
			cout << ans << "\n";
		}
		else {
			cout << s.size() << " " << s.size() - 1 << "\n";
		}
	}
}
int main()
{
	solve();
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值