Week15 实验 - A B C D F

A - AtCoder abc142_c

#include <cstdio>
#include <iostream>
const int MAXN = 1e5 + 5;
int ans[MAXN];
int main()
{
	int N;
	std::cin >> N;
	for (int i = 1; i <= N; i++)
	{
		int val;
		scanf("%d", &val);
		ans[val] = i;
	}
	for (int i = 1; i <= N; i++)
		printf(i == 1 ? "%d" : " %d", ans[i]);
	std::cout << std::endl;
	return 0;
}

B - CodeForces 499A

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct TIME
{
	int l, r;
	bool operator<(const TIME& x) const
	{
		return l < x.l;
	}
}sec[55];
int main()
{
	int N, X, ANS = 0;
	cin >> N >> X;
	for (int i = 1; i <= N; i++)
		scanf("%d %d", &sec[i].l, &sec[i].r);
	sort(sec + 1, sec + N + 1);
	for (int i = 1; i <= N; i++)
	{
		int restT = sec[i].l - sec[i - 1].r - 1;
		int num = restT / X;
		restT = restT - num * X;
		ANS += restT;
		ANS += sec[i].r - sec[i].l + 1;
	}
	cout << ANS << endl;
	return 0;
}

C - CodeForces 1076A

//如果当前字符不比后面的字符大,就不用删
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	int N;
	string s;
	cin >> N >> s;
	for (int i = 0; i < N - 1; i++)
	{
		if (s[i] <= s[i + 1]) continue;
		else
		{
			for (int j = 0; j <= i - 1; j++)
				cout << s[j];
			for (int j = i + 1; j < N; j++)
				cout << s[j];
			cout << endl;
			return 0;
		}
	}
	for (int i = 0; i < N - 1; i++)
		cout << s[i];
	cout << endl;
	return 0;
}

D - CodeForces 1328B

值得注意的是,K<2e9,但是8*K就会爆int,既然会爆int,就使用long long,为了防止算术溢出和精度问题,其他变量也用long long 和 long double,包括常量

//考虑b1和b2的位置
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	long long T, N, K;
	cin >> T;
	while (T--)
	{
		cin >> N >> K;
		long long GroupNum = ceil((-1.0L + sqrtl((long double)(1.0L + 8.0L * K))) / 2.0L);
		long long Offset = K - GroupNum * (GroupNum - 1) / 2;
		long long Pos1 = N - GroupNum;
		long long Pos2 = N - Offset + 1;
		for (long long i = 1; i <= N; i++)
		{
			if (i == Pos1 || i == Pos2)
				printf("b");
			else printf("a");
		}
		printf("\n");
	}
	return 0;
}

F - CodeForces 1153A

#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
const int MAXN = 1e6 + 5;
int bucket[MAXN];
int main()
{
	int N, D;
	cin >> N >> D;
	int ai, bi;
	for (int i = 1; i <= N; i++)
	{
		cin >> ai >> bi;
		if (ai > D)
		{
			bucket[ai] = i;
			continue;
		}
		int k = (D - ai) / bi;
		bucket[ai + k * bi] = i;
		bucket[ai + k * bi + bi] = i;
		bucket[ai + k * bi + bi + bi] = 1;
	}
	int i = D;
	while (1)
	{
		if (bucket[i])
		{
			cout << bucket[i] << endl;
			return 0;
		}
		++i;
	}
	return 0;
}

  

posted @ 2020-05-29 17:45  菜鸡今天学习了吗  阅读(126)  评论(0编辑  收藏  举报