2023-01-06做题记录
牛客网小白月赛65
A-牛牛去购物
题目描述
牛牛带着 n 元钱去超市买东西,超市一共只有两款商品,价格为 a 元的篮球和价格为 b 元的足球,牛牛想把手里的钱尽可能花光,请问牛牛最少能剩多少钱?
输入描述:
输入一行,三个正整数 n,a,b(1≤n,a,b≤1000),n 表示牛牛现有的钱数,a 表示一个篮球的单价,b 表示一个足球的单价。
输出描述:
输出一行一个整数,代表牛牛最少能剩下的钱数。
示例1
输入
7 5 3
输出
1
AC Code:
// 思路:暴力枚举
#include <iostream>
using namespace std;
int inf = (1 << 31) - 1;
int x, a, b;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);cin >> x >> a >> b;for (int i = 0; i <= 1000; i++){for (int j = 0; j <= 1000; j++){if (a * i + b * j > x)continue;elseinf = min(inf, x - (a * i + b * j));}}cout << inf;return 0;
}
P1003 [NOIP2011 提高组] 铺地毯
题目描述
为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯。一共有 n 张地毯,编号从 1 到 n。现在将这些地毯按照编号从小到大的顺序平行于坐标轴先后铺设,后铺的地毯覆盖在前面已经铺好的地毯之上。
地毯铺设完成后,组织者想知道覆盖地面某个点的最上面的那张地毯的编号。注意:在矩形地毯边界和四个顶点上的点也算被地毯覆盖。
输入格式
输入共n+2 行。
第一行,一个整数 n,表示总共有 n 张地毯。
接下来的 n 行中,第 i+1 行表示编号i 的地毯的信息,包含四个整数 a ,b ,g ,k,每两个整数之间用一个空格隔开,分别表示铺设地毯的左下角的坐标 (a,b) 以及地毯在 x 轴和 y 轴方向的长度。
第 n + 2行包含两个整数 x 和 y,表示所求的地面的点的坐标 (x, y)。
输出格式
输出共 1 行,一个整数,表示所求的地毯的编号;若此处没有被地毯覆盖则输出 -1
。
输入输出样例
输入
3
1 0 2 3
0 2 3 3
2 1 3 3
2 2
输出
3
输入
3
1 0 2 3
0 2 3 3
2 1 3 3
4 5
输出
-1
说明/提示
【样例解释 1】
如下图,1 号地毯用实线表示,2 号地毯用虚线表示,3号用双实线表示,覆盖点(2,2) 的最上面一张地毯是 3 号地毯。
【数据范围】
对于 30% 的数据,有n≤2。
对于50% 的数据,0≤a,b,g,k≤100。
对于100% 的数据,有 0≤a,b,g,k≤10^5,n<=10^4。
noip2011 提高组 day1 第 11 题。
AC Code:
#include <iostream>
using namespace std;
struct dt
{int a, b, x, y;
} d[10001]; // 数组往小开,以防炸空间
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);int n, xn, yn, di = -1; // 用di表示(xn,yn)上毯子覆盖的情况,初始值为-1cin >> n;for (int i = 1; i <= n; i++) // 输入每一张毯子的横坐标、纵坐标、长度、宽度cin >> d[i].a >> d[i].b >> d[i].x >> d[i].y;cin >> xn >> yn;for (int i = 1; i <= n; i++) // 用每一张毯子的数据进行比较if (xn >= d[i].a && xn <= d[i].a + d[i].x && yn >= d[i].b && yn <= d[i].b + d[i].y)// 判断该点在不在毯子范围内,d[i].a~d[i].a+d[i].x表示毯子在直角坐标系横坐标上的始末位置,即长度;// d[i].b~d[i].b+d[i].y表示毯子在纵坐标上的始末位置,即宽度di = i; // 若该点在地毯范围内,则将第i张地毯的数覆盖该点// 这种循环方法计算次数少,反正就很快就对了cout << di;
}
P1002 [NOIP2002 普及组] 过河卒
题目描述
棋盘上 A 点有一个过河卒,需要走到目标 B 点。卒行走的规则:可以向下、或者向右。同时在棋盘上 C 点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马的控制点。因此称之为“马拦过河卒”。
棋盘用坐标表示,A 点 (0,0)、B 点 (n,m),同样马的位置坐标是需要给出的。
现在要求你计算出卒从 A 点能够到达 B 点的路径的条数,假设马的位置是固定不动的,并不是卒走一步马走一步。
输入格式
一行四个正整数,分别表示 B 点坐标和马的坐标。
输出格式
一个整数,表示所有的路径条数。
输入输出样例
输入
6 6 3 3
输出
6
说明/提示
对于100% 的数据,1≤n,m≤20,0 ≤ 马的坐标≤20。
【题目来源】
NOIP 2002 普及组第四题
思路:
一个很经典的 DP 水题。
思路其实非常简单啊,就是小学奥数的标数法,相信各位应该都是非常熟悉的。
那递推公式就是
dp[i][j]=dp[i−1][j]+dp[i][j−1]
了。
注意讨论马的控制点不能进入就好了。还有注意开 long long
。
AC code:
#include <bits/stdc++.h>
using namespace std;
bool vis[25][25];
long long step[25][25];
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);step[0][0] = 1;int n, m, x, y;cin >> n >> m >> x >> y;vis[x][y] = 1;// 只对界内的控制点进行标记if (x - 2 >= 0 && y - 1 >= 0)vis[x - 2][y - 1] = 1;if (x - 2 >= 0 && y + 1 >= 0)vis[x - 2][y + 1] = 1;if (x + 2 >= 0 && y - 1 >= 0)vis[x + 2][y - 1] = 1;if (x + 2 >= 0 && y + 1 >= 0)vis[x + 2][y + 1] = 1;if (x - 1 >= 0 && y + 2 >= 0)vis[x - 1][y + 2] = 1;if (x - 1 >= 0 && y - 2 >= 0)vis[x - 1][y - 2] = 1;if (x + 1 >= 0 && y + 2 >= 0)vis[x + 1][y + 2] = 1;if (x + 1 >= 0 && y - 2 >= 0)vis[x + 1][y - 2] = 1;for (int i = 0; i <= n; i++){for (int j = 0; j <= m; j++){// 途径点要保证在界内if (vis[i][j - 1] == 0 && j - 1 >= 0){step[i][j] += step[i][j - 1];}if (vis[i - 1][j] == 0 && i - 1 >= 0){step[i][j] += step[i - 1][j];}}}cout << step[n][m];return 0;
}
问题 A: 辣椒炸弹
题目描述
植物大战僵尸这款游戏中,有一种植物武器叫辣椒炸弹,在草坪中的任意一格摆放它可以把草坪中该行上的所有僵尸瞬间消灭,也就是说,如果在第i行中任意位置摆放一个炸弹,第i行中的所有僵尸就瞬间都被杀死了。现在我们假定草坪有r行c列,草坪中有n只僵尸,僵尸不移动,现在给你k个樱桃炸弹,要求只能使用这k个炸弹来消灭这些僵尸,请问最多可以杀死多少只僵尸?
输入
第一行4个正整数r,c,k,n;
接下来n行,每行两个正整数x,y,表示第x行的第y列中有一只僵尸。
输出
第1行输出最多可以杀死的僵尸数;
第2行按顺序输出所有被消灭的行,如果有不同方案,输出字典序最小的那种方案。
样例输入
4 6 2 6
1 3
2 3
3 1
4 4
4 5
4 6
样例输出
4
1 4
提示
样例说明:可以杀死第1行和第4行的所有僵尸,方案(1,4),(2,4),(3,4)都是一样多的僵尸,但(1,4)的字典序最小。
对于30%的数据,0<r、c<=50,n<=2500;
对于100%的数据,0<r、c<=1000,n<=1000000,k<=r。
打上标记,排序即可.
The AC code is as follows:
#include <cstdio>
#include <algorithm>
using namespace std;
struct Edge
{int sum, id;
} book[1000010];
int sort_id[1010];
bool cmp(Edge x, Edge y)
{if (x.sum > y.sum)return true;if (x.sum == y.sum && x.id < y.id)return true;return false;
}
int main()
{int r, c, k, n, x, y;scanf("%d%d%d%d", &r, &c, &k, &n);for (int i = 1; i <= n; i++){scanf("%d%d", &x, &y);book[x].sum++;}for (int i = 1; i <= r; i++)book[i].id = i;sort(book + 1, book + 1 + r, cmp);int ans = 0;for (int i = 1; i <= k; i++)ans += book[i].sum;printf("%d\n", ans);for (int i = 1; i <= k; i++)sort_id[i] = book[i].id;sort(sort_id + 1, sort_id + 1 + k);for (int i = 1; i <= k; i++)printf("%d ", sort_id[i]);
}
问题 B: 金子数
题目描述
某地区有 n 条(编号依次为 1 到 n)互不交叉的道路,每条道路上都有 m 个数字,其中 能被 8 整除的数称为金子数,这个数字表示其重量。
如下表是 3 条道路,每条道路中有 5 个数的一种可能情况。
小华想在 n 条道路中走一条金子重量之和最大的道路,请编程帮他找出这条道路吧.
输入
输入共 n+1 行。
第 1 行两个整数 n 和 m,表示总共有 n 条道路,每条道路上有 m 个数。 接下来 n 行,每行 m 个正整数。
输出
输出共 1 行。 一个整数,表示金子重量之和最大的道路编号。
样例输入
3 5
13 24 17 8 23
1 2 3 4 5
16 2 16 4 8
样例输出
3
提示
输入的样例中,金子重量之和最大的道路编号为 3,具体情况见问题描述。
30%的测试点输入数据保证 1≤n≤10,1≤m≤100,路上的每个数都不超过 100。
100%的测试点输入数据保证 1≤n≤100,1≤m≤10000,路上的每个数都不超过 100000。 所有的测试点输入数据保证金子重量之和最大的道路只有一条,且肯定存在。
思路:一次计算出每条道路中金子数的和,并找出最大值.
The AC code is as follows:
#include <iostream>
using namespace std;
const int maxn = 1e4 + 10;
int gold[101][maxn];
int ans[101];
int n, m;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);cin >> n >> m;for (int i = 1; i <= n; i++){for (int j = 1; j <= m; j++){cin >> gold[i][j];}}for (int i = 1; i <= n; i++){for (int j = 1; j <= m; j++){if (gold[i][j] % 8 == 0)ans[i] += gold[i][j];}}int maxx = -10000, ans1 = 0;for (int i = 1; i <= n; i++)if (ans[i] > maxx){maxx = ans[i], ans1 = i;}cout << ans1;return 0;
}
问题 C: 最小乘积
题目描述
给定4个整数:a,b,x,y。刚开始a>=x,b>=y。你可以做如下操作不超过n次:
每次你可以选择a或者b,然后让它的值减少1;不过你要保证本次操作之后a的值不能小于x且b的值不能小于y。
问最多n次操作之后,a*b的最小值是多少?
输入
第一行,一个整数T,表示有T组测试数据。
接下来有T行,每行5个整数:a,b,x,y,n。
输出
共T行,每行一个整数。
样例输入
7
10 10 8 5 3
12 8 8 7 2
12343 43 4543 39 123212
1000000000 1000000000 1 1 1
1000000000 1000000000 1 1 1000000000
10 11 2 1 5
10 11 9 1 10
样例输出
70
77
177177
999999999000000000
999999999
55
10
提示
对于100%的数据满足1<=T<=20000,1<=a,b,x,y,n<=10^9。
解题思路
这题很简单,记录先给a和先给b的两种结果的成绩再比较,输出
注意:这道题出入范围到了十的9次方用long long定义变量
cin>>a>>b>>x>>y>>m;long long a1=a,b1=b,m1=m;if(a-x<m){m-=a-x; a=x; }else {a-=m;m=0;}if(b-y<m) b=y;else b-=m;
if(b1-y<=m1){m1-=b1-y; b1=y; }else {b1-=m1;m1=0;}if(a1-x<m1) a1=x;else a1-=m1;
long long c=a*b;long long d=a1*b1;if(d<c) cout<<d;else cout<<c;if(i!=n) cout<<endl;
话不多说放代码:
#include<iostream>
using namespace std;
int n;
long long a,b,x,y,m;
int main()
{cin>>n;for(int i=1;i<=n;i++){cin>>a>>b>>x>>y>>m;long long a1=a,b1=b,m1=m;if(a-x<m){m-=a-x; a=x; }else {a-=m;m=0;}if(b-y<m) b=y;else b-=m;if(b1-y<=m1){m1-=b1-y; b1=y; }else {b1-=m1;m1=0;}if(a1-x<m1) a1=x;else a1-=m1;long long c=a*b;long long d=a1*b1;if(d<c) cout<<d;else cout<<c;if(i!=n) cout<<endl; }return 0;
}
A. Theatre Square
The input contains three positive integer numbers in the first line: n, m and a (1 ≤ n, m, a ≤ 109).
Write the needed number of flagstones.
6 6 4
4
The AC code is as follows:
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
long long n, m, a, ans;
int main()
{cin >> n >> m >> a;ans = (ceil(n * 1.0 / a)) * (ceil(m * 1.0 / a));cout << ans;return 0;
}
A. Panoramix's Prediction
Pretests contain all the cases with restrictions 2 ≤ n < m ≤ 4.
Print YES, if m is the next prime number after n, or NO otherwise.
3 5
YES
7 11
YES
7 9
NO
The AC code is as follows:
#include <iostream>
using namespace std;
bool isprime(int n)
{if (n == 0 || n == 1)return 0;if (n == 2 || n == 3 || n == 5)return 1;if (n % 2 == 0 || n % 3 == 0)return 0;for (int i = 5; i * i <= n; i += 6)if (n % i == 0 || n % (i + 2) == 0)return 0;return 1;
}
int n, m;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);cin >> n >> m;if (n < m && isprime(n) && isprime(m)){for (int i = n + 1; i < m; i++){if (isprime(i)){cout << "NO";return 0;}}}else{cout << "NO";return 0;}cout << "YES";return 0;
}
A. Haiku
Haiku is a genre of Japanese traditional poetry.
Three phases from a certain poem are given. Determine whether it is haiku or not.
on codeforces
beta round is runninga rustling of keys
YES
how many gallons
of edo s rain did you drinkcuckoo
NO
The AC code is as follows:
#include <iostream>
using namespace std;
int main()
{string a, b, c;getline(cin, a);getline(cin, b);getline(cin, c);int cnt = 0;for (int i = 0; i < a.size(); i++){if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u')cnt++;}if (cnt != 5){cout << "NO";return 0;}cnt = 0;for (int i = 0; i < b.size(); i++){if (b[i] == 'a' || b[i] == 'e' || b[i] == 'i' || b[i] == 'o' || b[i] == 'u')cnt++;}if (cnt != 7){cout << "NO";return 0;}cnt = 0;for (int i = 0; i < c.size(); i++){if (c[i] == 'a' || c[i] == 'e' || c[i] == 'i' || c[i] == 'o' || c[i] == 'u')cnt++;}if (cnt != 5){cout << "NO";return 0;}cout << "YES";return 0;
}
A. Way Too Long Words
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
4
word
localization
internationalization
pneumonoultramicroscopicsilicovolcanoconiosis
word
l10n
i18n
p43s
The AC code is as follows:
#include <iostream>
using namespace std;
int t;
string str;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);cin >> t;while (t--){cin >> str;if (str.size() < 11)cout << str << "\n";elsecout << str[0] << str.size() - 2 << str[str.size() - 1] << "\n";}
}
A. Triangular numbers
Your task is to find out if a given integer is a triangular number.
The first line contains the single number n (1 ≤ n ≤ 500) — the given integer.
If the given integer is a triangular number output YES, otherwise output NO.
1
YES
2
NO
3
YES
The AC code is as follows:
#include <iostream>
using namespace std;
int n;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);cin >> n;for (int i = 1; i <= 40; i++){if (n == i * (i + 1) >> 1){cout << "YES";return 0;}}cout << "NO";return 0;
}
A. Sleuth
The English alphabet vowels are: A, E, I, O, U, Y
The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z
Is it a melon?
NO
Is it an apple?
YES
Is it a banana ?
YES
Is it an apple and a banana simultaneouSLY?
YES
思路:
先把所有字母统一成为小写字母,然后从倒数第二个字符(最后一个字符是?),往前找,找第一个字母,判断它是哪个分类里面的即可.
The AC code is as follows:
#include <iostream>
using namespace std;
string str;
int main()
{getline(cin, str);int len = str.size();for (int i = 0; i < len; i++){if (isupper(str[i]))str[i] = tolower(str[i]);}for (int i = len - 2; i >= 0; i--){if (str[i] == ' ')continue;else if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' || str[i] == 'y'){printf("YES");return 0;}else{printf("NO");return 0;}}return 0;
}
A. Word
HoUse
house
ViP
VIP
maTRIx
matrix
思路:
记录字符串中小写字母和大写字母的个数,然后比较,针对两种情况分别作出处理.
The AC code is as follows:
#include <iostream>
using namespace std;
int lower, upper;
string str;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);cin >> str;int len = str.size();for (int i = 0; i < len; i++)if (islower(str[i]))lower++;else if (isupper(str[i]))upper++;if (upper > lower){for (int i = 0; i < len; i++){if (islower(str[i]))str[i] = toupper(str[i]);}cout << str;}else{for (int i = 0; i < len; i++){if (isupper(str[i]))str[i] = tolower(str[i]);}cout << str;}return 0;
}
2023-01-06做题记录相关推荐
- 2020.9月做题记录
八月的做题记录因为是暑假所以鸽掉了. 离联赛真的不远了,要继续努力啊qwq- week -1 2020.08.30 2020.08.30 今天考试,修了20+次锅,修的我都没有心情做题了- 然后开始消 ...
- Regional 做题记录 (50/50)
写在前面 博主深感自己太弱了QAQ 于是有了一个刷水的想法,Regional的题目还是有很多考查思维的题目,所以这次是乱做50道思考题,可能会顺带做一些水题,这些题的简要题解会写到这篇博文里面,希望能 ...
- 2020.7月做题记录
转眼就到了2020的下半年了-前方仍是一片茫然. 长期计划 prufer 序列 2020.07.02-2020.07.04 Problem Finished P2624 [HNOI2008]明明的烦恼 ...
- 退役前的做题记录1.0
退役前的做题记录1.0 租酥雨最近很懒qwq,具体表现在写题的时候不想发题解了. 但是想想这样也不太好,就决定发个一句话(半句话到几句话不等)题解上来. 2018-09.18-2018-09.28 [ ...
- 退役前的做题记录2.0
退役前的做题记录2.0 最近在刷省选题......大致上是按照省份刷的. 不过上面的题目顺序是按照写题的顺序排列的,所以可能会有点乱哈. [BZOJ2823][AHOI2012]信号塔 最小圆覆盖,随 ...
- 概率期望题(期望 DP)做题记录
概率期望题(期望 DP)做题记录 P3830 [SHOI2012]随机树 难点在于第二问:生成树的期望深度. 不 wei zhuo 捏,设 \(dp_{i,j}\) 表示已经有了 \(i\) 个叶子结 ...
- 数数题(计数类 DP)做题记录
数数题(计数类 DP)做题记录 CF1657E Star MST 我们称张无向完全图是美丽的当且仅当:所有和 \(1\) 相连的边的边权之和等于这张完全图的最小生成树的边权之和. 完全图点数为 \(n ...
- CSDN 第六期编程竞赛做题记录
CSDN 第六期编程竞赛做题记录 -- CSDN编程竞赛报名地址:https://edu.csdn.net/contest/detail/16 9.18周日闲来无视写一下 csdn 的编程题,每期编程 ...
- 退役前的做题记录5.0
退役前的做题记录5.0 出于某种原因新开了一篇. [CodeChef]Querying on a Grid 对序列建立分治结构,每次处理\((l,mid,r)\)时,以\(mid\)为源点建立最短路树 ...
- 【Pikachu】漏洞练习平台做题记录+原理解析(2.2)XSS姿势和技巧
前言 Pikachu是一个带有漏洞的Web应用系统,在这里包含了常见的web安全漏洞. 如果你是一个Web渗透测试学习人员且正发愁没有合适的靶场进行练习,那么Pikachu可能正合你意. pikach ...
最新文章
- 剑指offer_第2题_替换空格
- Node学习9-gulp
- 基于弹性束图匹配的人脸识别
- Swift2.1 语法指南——自动引用计数
- 学习鸟哥的Linux私房菜笔记(1)——Linux系统入门
- 校招需要看的书 巩固的知识
- [转载] Bitmap的秘密
- 翻译 - 【Dojo Tutorials】Part 2 - Developing a Dojo Mobile Application: FlickrView
- 《腾讯iOS测试实践》一一1.8 小结
- Atitit 未来数据库新特性展望目录1. 统一的翻页 21.1. 2 Easy Top-N
- 数据结构c语言版第二版(严蔚敏)第一章笔记
- 英国政府将投资11.4亿英镑部署FTTP和开发5G
- 【微服务】使用yml格式进行nacos拓展配置
- 微信html页面缓存问题,浅谈微信页面入口文件被缓存解决方案_简单_前端开发者...
- 【python】7-4 p019车牌限号
- 最新:基于MAXENT模型的生物多样性生境模拟与保护优先区甄选、自然保护区布局优化评估及论文写作技巧
- 用turtle画美国队长盾牌
- 来看一看滑动时间窗格
- 计算机毕业设计springboot小组学习系统
- 华为stb工具遇到的问题求大神帮忙
热门文章
- 一帐Camplus联手AFIONA妍丽打造露营防晒包,呈现露营跨界新玩法
- 云计算灾难恢复双副本原理_云环境中的灾难恢复
- SQLAlchemy Async
- 2021高考校考类成绩查询山东,教育知识:2021山东工艺美术学院校考成绩查询艺术校考成绩查询时间及入口...
- 数据库多表联合查询附简单例子
- java计算机毕业设计仓库管理系统源程序+mysql+系统+lw文档+远程调试
- 视频传输——1.AVC/H.264
- 互联网之子–Aaron Swartz
- Udacity CS101 笔记
- word文档docx解密去除限制,word文档docx复制打印限制怎么解除?