Codeforces Round #739 (Div. 3)

文章目录

A

Polycarp doesn’t like integers that are divisible by 3 or end with the digit 3 in their decimal representation.t (1≤t≤100) k (1≤k≤1000)
题意: 找出第 k 个既不是 3 的倍数,也不是以 3 结尾的正整数。
思路: 打表 找出符合条件的前 1000 个数

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int a[1005];

int main() {
	IOS;
	int cnt = 0;
	for (int i = 1; cnt <= 1001; i ++) {
		if (i % 3 == 0 || i % 10 == 3) continue;
		a[++ cnt] = i;
	}
	int t; cin >> t;
	while (t --) {
		int k; cin >> k;
		cout << a[k] << "\n";
	} 
	return 0;
} 

B

Some number of people (this number is even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise starting from a person with the number 1. Each person is looking through the circle’s center at the opposite person.
You don’t know the exact number of people standing in the circle (but this number is even, no doubt). It is known that the person with the number a is looking at the person with the number b (and vice versa, of course). What is the number associated with a person being looked at by the person with the number c? If, for the specified a, b, and c, no such circle exists, output -1.

题意: 偶数圈(编号1到n)两两相对,给出其中一对a和b,求c所对的数字
思路: 规律相对应的数字差为 n / 2, 答案为(c + n / 2 - 1) % (n / 2) + 1
当a, b, c中有数字 > n 时,答案不存在

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main() {
	IOS;
	int t; cin >> t;
	while (t --) {
		int a, b, c;cin >> a >> b >> c;
		int n = 2 * abs(a - b);
		if (a > n || b > n || c > n) cout << -1 ;
		else cout << ((c + n / 2 - 1) % n + 1) ;
		cout << '\n';
	} 
	return 0;
} 

C

在这里插入图片描述

在这里插入图片描述
题意: 求一个数字 k 在图中的坐标
思路: 看图知,坐标中有一个为sqrt(k),关键在于求另一个坐标,分情况讨论。

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main() {
	IOS;
	int t; cin >> t;
	while (t --) {
		int k; cin >> k;
		int x = ceil(sqrt(k));
		int t = k - (x - 1) * (x - 1);
		if (t <= x) cout << t << ' ' << x << '\n';
		else cout << x << ' ' << (2 * x - t) << '\n';
	}
	return 0;
}

D

You are given an integer n. In 1 move, you can do one of the following actions:

  • erase any digit of the number (it’s acceptable that the number before the operation has exactly one digit and after the operation, it is “empty”);

  • add one digit to the right.
    The actions may be performed in any order any number of times.
    t (1≤t≤104) n (1≤n≤109)
    题意: 通过两种操作,把一个数字 k 变为2的整数幂,求最小操作次数
    思路: 最差的情况是,k 为9位数,删去所有的位后添上一个一位的2次幂,所以答案的2的整数幂,(<=1e18);用字符串处理,枚举2的整数幂,与k从高位依次匹配,记录最多匹配的位数(即k中保留的位数)。
    公式:操作次数 = 删除位数(k的总位数 - k保留的位数) + 填补位数(2的整数幂对应位数 - k保留位数)

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main() {
	IOS;
	int t; cin >> t;
	while (t --) {
		string s; cin >> s;
		int res = 10; // 最差 删去所有的数字(9个) 添 2、4、8 
		for (int i = 0; i < 64; i ++) { // 最多到 1e18  
			string t = to_string (1ULL << i);
			int k = 0;
			const int & sn = s.size(), tn = t.size();
			for (int j = 0; j < sn; j ++) {
				if (k < tn && s[j] == t[k]) k ++; // 未匹配完 t 中的数字 并且 对应位匹配 
			}
			res = min(res, tn + sn - 2 * k); 
		}
		cout << res << '\n';
	}
	return 0;
}

E

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值