cf刷题(800分场)+牛客周赛51轮补提+abc360

Problem - 1989A - Codeforces

太菜了,只能写800分的题目练练手了

题目大意:

思路:

我们只需要判断能否在硬币掉落之前提前或刚好到达硬币的正下方即可

代码:

void solve()
{
	int n;
	cin >> n;
	int x, y;
	for (int i = 0; i < n; i++)
	{
		cin >> x >> y;
		int t = (x == 0 ? 0 : abs(x));
		int yy = -t;
		if (y - t >= yy - 1)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

Problem - 1987A - Codeforces

800分的菜鸟题

思路:

对k=1和n=1的情况特判一下,然后我们不难知道,k内最多上传1gb,在k+1时也上传1gb(为了得到最小值),然后推出公式即可

代码:

void solve()
{
	int n, k;
	cin >> n >> k;
	if (k == 1)
	{
		cout << n << endl;
		return;
	}
	if (n == 1)
	{
		cout << 1 << endl;
		return;
	}
	else
	{
		cout << (n - 1) * k + 1 << endl;
		return;
	}
}

Problem - 1986A - Codeforces

思路:

数据范围很小,直接枚举从1到10就行

代码:

void solve()
{
	int x1, x2, x3;
	cin >> x1 >> x2 >> x3;
	int ans = 100; 
	int sum;
	for (int i = 1; i <= 10; i++)
	{
		sum = abs(x1 - i) + abs(x2 - i) + abs(x3 - i);
		if (ans > sum)ans = sum;
	}
	cout << ans << endl;
}

Problem - 1984A - Codeforces(最开始没看到数组是递增的,服了)

思路:

判断数组极值是否为0,不是的话任选一个数单独一组,其余数一组即可(不能选边界两个数)

代码:

void solve()
{
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	vector<char>b(n, 'B');
	if (a[n - 1] - a[0] != 0)
	{
		b[1] = 'R';
		cout << "YES" << endl;
		for (int i = 0; i < n; i++)
			cout << b[i];
		cout << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}

C-小红充电_牛客周赛 Round 51 (nowcoder.com)

思路:

刚写的时候没考虑周全,只判断了两种情况(能快充和不能快充),其实还有一个情况(在不能快充时我们把电量消耗到可以快充的大小,再进行快充,最后判断一下哪一种情况的耗电量最小即可)

代码:

void solve()
{
	ll x, y, t, a, b, c;
	cin >> x >> y >> t >> a >> b >> c;
	double ans = 0, res = 0;
	if (x <= t)
	{
		ans = (100 - x) * 1.0 / c;
		res = (100 - x) * 1.0 / c;
	}
	else
	{
		res += (x - t) * 1.0 / y;
		res += (100 - t) * 1.0 / c;
		ans = (100 - x) * 1.0 / b;
	}
	ans = min(ans, res);
	printf("%.9lf", ans);
	return;
}

E-小红走矩阵_牛客周赛 Round 51 (nowcoder.com)

一直给我报编译错误也不知道为啥(vs和dev都不报错,就牛客报错)

思路:

看到最短直接开始bfs,我们从数据范围的两头进行二分广搜,一步步缩小数据范围,最后直接输出就行了

代码:

//一直编译错误,该死的牛客网
ll vis[505][505];
ll a[505][505];
int n;
int bfs(int ans)
{
	if (a[1][1] > ans)
		return 0;
	queue<int>p, q;
	p.push(1);
	q.push(1);
	vis[1][1] = 1;
	int next[4][2] = { {0,1},{0,-1},{1,0},{-1,0} };
	while (!q.empty())
	{
		int xx = p.front();
		int yy = q.front();
		p.pop();
		q.pop();
		for (int i = 0; i < 4; i++)
		{
			int tx = xx + next[i][0];
			int ty = yy + next[i][1];
			if (tx<1 || tx>n || ty<1 || ty>n || a[tx][ty] > ans || vis[tx][ty] == 1)continue;
			else
			{
				vis[tx][ty] = 1;
				p.push(tx);
				q.push(ty);
				if (tx == n && ty == n)
					return 1;
			}
		}
	}
}
void solve()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			cin >> a[i][j];
		}
	}
	int l = 0, r = 1e9;
	while (l < r)
	{
		int mid = (l + r) >> 1;
		if (bfs(mid))
			r = mid;
		else
			l = mid + 1;
	}
	cout << l << endl;
	return;
}

B - Vertical Reading (atcoder.jp)

思路:

void solve()
{
	string s, t;
	cin >> s >> t;
	for (int i = 1; i < s.size(); i++)
	{
		for (int j = 0; j < i; j++)
		{
			string now = "";
			for (int k = j; k < s.size(); k++)
			{
				now += s[i];
			}
			if (now == t)
			{
				cout << "Yes" << endl;
				return;
			}
		}
	}
	cout << "No" << endl;
}

C - Move It (atcoder.jp)

思路:

每个盒子里只能放一个物品,我们找到盒子里多于一个物品盒子,把最大的留下,小的全部转移即可

代码:

void solve()
{
	int n;
	cin >> n;
	vector<int>a(n);
	vector<int>w(n);
	vector<int>z(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> w[i];
	for (int i = 0; i < n; i++)
	{
		a[i]--;
		z[a[i]] = max(z[a[i]], w[i]);
	}
	int sum1 = accumulate(w.begin(), w.end(), 0);
	int sum2 = accumulate(z.begin(), z.end(), 0);
	int ans = sum1 - sum2;
	cout << ans << endl;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值