codeforces练习

题解:若我们想要nk的数里有123456789和额外的d,由于123456789d不一定是n的倍数,那么我们可以给他加上一些数使其成为倍数,我们只需构造出123456789d000...的形式最后加上(n-x)%n,再除以n即可。 

#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
#include<vector>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
#define vi vector<LL>
#define pu push_back
int c[214514];
const int N = 1145141;
const int M = 1234567890;
//a[i]<=x+k*bi and a[i]+k*b[i]>=x;
LL pow1(LL a, LL b)
{
	LL res = 1;
	while (b > 0) {
		if (b & 1) res *= a;
		a *= a;
		b >>= 1;
	}
	return res;
}
int main() {
	int t;
	cin >> t;
	while (t--)
	{
		LL n, d;
		cin >> n >> d;
		LL ans = 1234567890 + d;
		ans *= pow1(10, log10(n) + 1);
		cout << (ans + n - 1) / n << endl;
	}
}

 B.

题解:贪心,将探测器价格由低到高排序,依次看能买多少个探测器 

//#include<iostream>
//#include<algorithm>
//#include<cstring>
//#include<map>
//#include<vector>
//#include<deque>
//#include<set>
//using namespace std;
//typedef pair<int, int> PII;
//int c[214514];
//const int N = 1010;
//int main() {
//	int n;
//	cin >> n;
//	vector<PII> q;
//	memset(c, 0, sizeof c);
//	for (int i = 1; i <= n; i++) {
//		cin >> c[i];
//		q.push_back({ c[i],i });
//	}
//	sort(q.begin(), q.end());
//	int ans = 0;
//	int sum = 0;
//	int it = 0;
//	for (auto p : q) {
//		if (p.second < it) continue;
//		sum += (p.second - it);//第几轮。
//		it = p.second;
//		int w = p.first;
//		ans += (sum) / w;//购买的。
//		sum -= (sum / w * w);//剩的币
//	}
//	cout << ans ;
//}

 F.

签到,在满足前两个条件下,将每个字符依次插入容器,判断大小是否为4. 

#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<deque>
#include<set>
using namespace std;
const int N = 1010;
int main() {
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		if (s.size() == 5 && (s[2] == s[4]))
		{
			set<char>s1;
			for (int j = 0; j < s.size() - 1; j++)
			{
				s1.insert(s[j]);
			}
			if (s1.size() == 4) sum++;
		}
	}
	cout << sum;

		


}

 J。

题解:由样例可发现,若n的每个位上的数都是奇数,那么直接输出97531即可,若有偶数,将其位置记录下来,最后输出即可,因为最后以为是偶数,一定可以拆成两个数相乘 

//#include<iostream>
//#include<algorithm>
//#include<cstring>
//#include<map>
//#include<vector>
//using namespace std;
//typedef pair<int, int> PII;
//typedef long long LL;
//int c[214514];
//const int N = 1145141;
//int n;
a[i]<=x+k*bi and a[i]+k*b[i]>=x;
//void solve() {
//	string s;
//	cin >> s;
//	vector<LL>a(20);
//	int pos= -0x3f3f3f3f;
//	bool flag = false;
//	for (int i = 0; i < s.size(); i++)
//	{
//		a[i] = s[i] - '0';
//	}
//	for (int i = 0; i < s.size(); i++)
//	{
//		if (a[i] % 2 == 0) {
//			flag = true;
//			pos = i;
//		}
//	}
//	if (!flag){
//		cout << "97531" << endl;
//		return;
//	}
//	for (int i = 0; i < s.size(); i++) {
//		if (pos == i) {//找到偶数了,最后输出。
//			continue;
//		}
//		cout << a[i];
//	}
//	cout << a[pos] << endl;
//}
//int main() {
//	int t;
//	cin >> t;
//	while (t--) {
//		solve();
//	}
//}

 M。

题解:二分答案即可。 

//#include<iostream>
//#include<algorithm>
//#include<cstring>
//#include<map>
//#include<vector>
//using namespace std;
//typedef pair<int, int> PII;
//typedef long long LL;
//int c[214514];
//const int N = 1145141;
//LL a[N], b[N];
//int n;
a[i]<=x+k*bi and a[i]+k*b[i]>=x;
//bool check(LL x) {
//	LL l = -0x3f3f3f3f, r = 0x3f3f3f3f;
//	for (int i = 1; i <= n; i++) {
//		l = max(l, a[i] - x * b[i]);
//		r = min(r, a[i] + x * b[i]);
//	}
//	return l <= r;
//}
//void solve() {
//	cin >> n;
//	for (int i = 1; i <= n; i++) {
//		cin >> a[i];
//	}
//	for (int i = 1; i <= n; i++) {
//		cin >> b[i];
//	}
//	int l = 0, r = 1e11;
//	while (l < r) {
//		int mid = (l + r) >> 1;
//		if (check(mid)) {
//			r = mid;
//		}
//		else l = mid + 1;
//	}
//	cout << l << endl;
//}
//int main() {
//	int t;
//	cin >> t;
//	while (t--) {
//		solve();
//	}
//}

 L.

题解:由于n行的总时间最多为n秒,所以总bug数不多于22个, 状态方程可写为:dp[j]+i+pow1(i-j,4).

//#include<iostream>
//#include<algorithm>
//#include<cstring>
//#include<map>
//#include<cmath>
//#include<vector>
//using namespace std;
//typedef pair<int, int> PII;
//typedef long long LL;
//int c[214514];
//const int N = 1145141;
a[i]<=x+k*bi and a[i]+k*b[i]>=x;
//LL pow1(LL a, LL b)
//{
//	LL res = 1;
//	while (b>0) {
//		if (b & 1) res *= a;
//		a *= a;
//		b >>= 1;
//	}
//	return res;
//}
//int main() {
//	int n, m;
//	cin >> n >> m;
//	vector<LL>a(n+m);
//	vector<LL> dp(n + m);
//	for (int i = 1; i <= m; i++) {
//		cin >> a[i];
//	}
//	for (int i = 1; i <= m; i++) {
//		dp[i] = 1981000000;
//	}
//	for (int i = 1; i <= m; i++) {
//		for(int j = i-1; j>=max(0,i-22); j--) {
//			dp[i] = min(dp[i], dp[j] + pow1(i-j,4)+a[i]);
//		}
//	}
//	cout << dp[m];
//}

 D.

 题解:可以得到性质:结果一定出现在横坐标相邻的点对上,所以只需按横坐标排序后算一边相邻点的答案,取最大值即可

#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
#include<vector>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
#define vi vector<LL>
#define pu push_back
int c[214514];
const int N = 1145141;
const int M = 1234567890;
int n;
//a[i]<=x+k*bi and a[i]+k*b[i]>=x;
LL pow1(LL a, LL b)
{
	LL res = 1;
	while (b > 0) {
		if (b & 1) res *= a;
		a *= a;
		b >>= 1;
	}
	return res;
}
bool cmp(PII a, PII b)
{
	return a.first + a.second < b.first + b.second;
}
double dist(PII a, PII b) {
	auto p1 = a;
	auto p2 = b;
	return (abs(p1.first - p2.second) + abs(p1.second - p2.second) / sqrt((p1.first - p2.second) * (p1.first - p2.second) + (p1.second - p2.second) * (p1.second - p2.second)));
}
PII a[N];
int main() {
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n;
		for (int i = 1; i <= n; i++) {
			auto p = a[i];
			cin >> p.first >> p.second;
		}
		sort(a + 1, a + 1 + n, cmp);
		double ans = 1;
		for (int i = 2; i <= n; i++)
		{
			ans = max(ans, dist(a[i - 1], a[i]));
		}
		cout << ans << endl;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值