A PizzaForces
题目大意
给你一个数n,和3种披萨6块15分钟,8块20分钟,10块25分钟,问最少多少分钟能凑齐至少n块披萨
主要思路
我们先观察到3种披萨都是2.5分钟一块,然后考虑奇数情况,由于披萨都是偶数,我们只能凑成比奇数大1的偶数。于是只剩偶数情况
- 小于等于6的偶数都只能买6块15分钟
- 大于等于6的偶数题目中给出了6 8 10能凑出,于是我们观察6+6 = 12, 6 + 8 = 14,6 + …可以观察到所有偶数都能凑出,所以只需要判断有多少块每块2.5min即可
AC代码
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
cout << max(6LL, n + 1) / 2 * 5 << '\n';
}
}
B Two Tables
题目大意
给定一个大矩形,和一个小矩形,问能不能通过移动小矩形在大矩形范围内再放入一个小矩形,不能输出-1
主要思路
如果新放入的小矩形有一条边大于大矩形输出-1
否则,我们先判断当前能不能放入小矩形,能输出0
否则,我们仅通过上下移动小矩形或者左右移动小矩形 如果有一侧能放下两个矩形,那么另一侧他们两个互不影响
AC代码
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << " = " << a << endl;
#define x first
#define y second
typedef long long ll;
const int N = 200010;
int main(void)
{
int T;
cin >> T;
while(T--)
{
int W, H, x1, y1, x2, y2, w, h;
cin >> W >> H >> x1 >> y1 >> x2 >> y2 >> w >> h;
double ans;
int x = x2 - x1, y = y2 - y1;
if(x + w > W && y + h > H) cout << -1 << endl;
else
{
int ansx, ansy;
int nx = max(W - x2, x1), ny = max(H - y2, y1);
if(x + w <= W) ansx = max(0, w - nx);
else ansx = 1e8;
if(y + h <= H) ansy = max(0, h - ny);
else ansy = 1e8;
printf("%.8lf\n", (double)min(ansx, ansy));
}
}
return 0;
}
C Coin Rows
题目大意

Alice先从左上角走到右下角,走过的格子值都变为0,然后Bob再从左上角走到右下角,两人都采取最优策略,问Bob所经过的所有格子和最小是多少
图中红色为Alice,蓝色为Bob
主要思路
观察Alice把棋盘分为了两部分,而Bob在第二次走的过程中只能走期中一部分,所以我们枚举Alice将在哪个点向下走,每次都将棋盘分为两部分,每次取两部分的最大值,结果取每次最大值的最小值即可
AC代码
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << " = " << a << endl;
#define x first
#define y second
typedef long long ll;
const int N = 200010;
ll n, m, a[3][N], s[3][N];
ll f[3][N];
int main(void)
{
int T;
cin >> T;
while(T--)
{
memset(s, 0, sizeof(s));
cin >> m;
for(int i = 1; i <= 2; i++)
{
for(int j = 1; j <= m; j++)
{
cin >> a[i][j];
s[i][j] = s[i][j - 1] + a[i][j];
}
}
ll ans = 1e18;
for(int i = 1; i <= m; i++)
{
ans = min(ans, max(s[1][m] - s[1][i], s[2][i - 1]));
}
cout << ans << endl;
}
return 0;
}
D Say No to Palindromes
题目大意
给定一个仅由a, b, c三个字母组成的字符串,有m次询问,每次询问给定一个区间l,r,问最少修改多少个字母能使l, r这个区间不存在回文子串
主要思路
先思考什么情况不会出现回文子串,a,b,c的排列一共有6种,我们任意取出两个排列合并发现都会有回文子串,于是一个字符串按3个字母一组划分仅由一个排列组成则无回文子串,比如abcab, acbacba。
所以我们处理长度为n的字符串时处理6种排列从1~n如何修改即可
每次询问的答案即为6种排列的最小值
AC代码
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << " = " << a << endl;
#define x first
#define y second
typedef long long ll;
const int N = 200010;
int n, m, f[10][N];
string t[10];
char s[N];
int main(void)
{
int T;
T = 1;
while(T--)
{
scanf("%d%d", &n, &m);
scanf("%s", s + 1);
t[1] = "abc", t[2] = "acb", t[3] = "bac", t[4] = "bca", t[5] = "cab", t[6] = "cba";
for(int i = 1; i <= 6; i++)
{
for(int j = 1; j <= n; j++)
{
f[i][j] = f[i][j - 1];
if(s[j] != t[i][j % 3]) f[i][j]++;
}
}
while(m--)
{
int l, r;
scanf("%d%d", &l, &r);
int ans = n + 1;
for(int i = 1; i <= 6; i++)
{
ans = min(ans, f[i][r] - f[i][l - 1]);
}
cout << ans << endl;
}
}
return 0;
}
本文解析了四道编程竞赛题目,包括最少时间凑齐披萨数量、放置矩形、两人交替行走路径求和及消除回文子串等问题,提供了解题思路及AC代码。
1314

被折叠的 条评论
为什么被折叠?



