- 博客(21)
- 资源 (1)
- 问答 (1)
- 收藏
- 关注
原创 计蒜客超级书架2题解
题目链接: https://nanti.jisuanke.com/t/T1736首先这道题是一道典型的DFS题。我们需要用DFS枚举最小距离,就行了。首先需要头文件和定义:#include<iostream>#include<cstdio>//在计蒜客写代码是需要文件读写的,本头文件就是做准备的。using namespace std;int n,b,minn=0x3f3f3f3f,h[25];然后我们要先写主函数部分:int main(){ freopen
2021-10-16 19:56:48
381
原创 NOIP2016提高组 玩具谜题
题目来源(洛谷站):传送门想要ctj的人直接跳过下列内容这道题作为一道提高组的题目,还是比较简单的。洛谷给出的难度为普及-。首先我的第一个反应是用结构体模拟链表,每个结构体中包含名字、左边小人的编号、右边小人的编号以及朝外还是朝内。结构体部分代码↓struct node{ string name; int left,right; bool wn;}a[100005];然后就写下去就好了但是其实,left和right完全是浪费,直接一个bool类型表示外内就好了,数一
2021-09-11 18:10:37
255
原创 洛谷P1618三连击(升级版)
这道题的思路是将第一个数进行枚举,按比例分配第二个数和第三个数,用函数判断其合法性。由于铁定是三位数,所以函数部分不是很难,不需要一位一位挨着去检查。贴代码:#include<bits/stdc++.h>using namespace std;int a,b,c;bool book[10],flag;void fj(int x){//这个函数是用于进行判断是否将1-9全部填入。//由于只有9个数,所以如果有重复的必定有其他数字没有出现过。 book[x%10]=1;
2021-08-03 21:50:25
325
原创 洛谷P1059 [NOIP2006 普及组] 明明的随机数
原题:https://www.luogu.com.cn/problem/P1059这道题让我深深体会到STL容器的厉害。如果进行常规的去重和排序,需要的代码量很大,不过STL里面有一个set,专门去重和排序,时间复杂度很小。代码:#include<bits/stdc++.h>using namespace std;set<int> s;int main(){ int n,g; cin >> n; for(int i = 1; i <
2021-06-30 14:40:12
306
原创 洛谷P1008 [NOIP1998 普及组] 三连击
原题:https://www.luogu.com.cn/problem/P1008这道题你可以进行打表操作,不过我觉得太烦了,直接来九重for循环,不错。#include<bits/stdc++.h>using namespace std;int main(){ int i[9]; for (i[0] = 1; i[0] <= 9; i[0]++){ for (i[1] = 1; i[1] <= 9; i[1]++){
2021-06-30 14:37:20
224
原创 洛谷P1923 【深基9.例4】求第 k 小的数
原题:https://www.luogu.com.cn/problem/P1923这道题我想不出比nth_element更好的办法了。代码:#include<bits/stdc++.h>using namespace std;long long n,k,a[5000010];int main(){ scanf("%d%d",&n,&k); for(int i=0;i<n;i++)scanf("%d",&a[i]); nth_ele
2021-06-30 14:29:12
272
原创 洛谷P1090[NOIP2004提高组]合并果子
原题:https://www.luogu.com.cn/problem/P1090这道题虽然说是提高组,但只要运用一定的技巧,就一点儿也不难了。STL中,有一个优先队列(priority_queue),一般用于解决像这样一类的贪心问题。代码如下:#include<bits/stdc++.h>using namespace std;priority_queue<int,vector<int>,greater<int> >q;//如果要它从大到小出队列,直
2021-06-27 15:32:50
222
原创 洛谷P1049[NOIP2001普及组]装箱问题
原题:https://www.luogu.com.cn/problem/P1049一道01背包问题,不过比采药要简单,可以根据采药代码改编而成。代码如下:#include<bits/stdc++.h>using namespace std;int m,n; int f[20010];int w[40];int main(){ cin >> m >> n; for(int i=1;i<=n;i++)cin
2021-06-27 15:15:24
390
原创 洛谷P1046[NOIP2005 普及组]陶陶摘苹果
原题:https://www.luogu.com.cn/problem/P1046这道题也算是NOIP普及组的一个大水题了,所以洛谷给这道题判定为入门级别。代码如下:#include<bits/stdc++.h>using namespace std;int a[11];int main(){ for(int i = 1; i <= 10; i++)cin >> a[i]; int n; cin >> n; n += 30
2021-06-27 15:06:00
207
原创 洛谷P1093 [NOIP2007 普及组] 奖学金
原题:https://www.luogu.com.cn/problem/P1093这道题用结构体轻轻松松地就可以搞定。代码如下:#include<bits/stdc++.h>using namespace std;int n;struct student{ int h,a,b,c,sum;};//☆☆☆记住这里要写分号!bool cmp(student n1,student n2){ if(n1.sum < n2.sum)return 0; else i
2021-06-25 14:34:27
245
原创 洛谷P3954 [NOIP 2017 普及组] 成绩
这道题目测NOIP普及组有史以来最最最简单的一道题,只是千万不要想太多用double类型,很容易入坑,直接int就很好啊。代码如下:#include<bits/stdc++.h>using namespace std;int main(){ int a,b,c; cin >> a >> b >> c; cout << a * 0.2 + b * 0.3 + c * 0.5; return 0;}...
2021-06-25 14:30:37
294
原创 OpenJudge -3532:最大上升子序列和
原题:http://noi.openjudge.cn/ch0206/3532/这道题和1759那道题差不多,也不多讲了。#include<bits/stdc++.h>using namespace std;int a[1010],ans[1010],sum;int main(){ int n; cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; ans[i] = a[i];
2021-06-25 14:23:42
125
原创 OpenJudge -1759:最长上升子序列
原题:http://noi.openjudge.cn/ch0206/1759/这道题,基础动态规划,不多讲了,直接上代码。#include<bits/stdc++.h>using namespace std;int n,a[1010],dp[1010],ans;int main(){ cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; dp[i] = 1; } for(int i = 1;
2021-06-25 14:18:47
182
原创 OpenJuge -1944:吃糖果
原题:http://noi.openjudge.cn/ch0206/1944/这道题实际上就是一个去掉第一个数的斐波那契数列,直接递推就得了。代码如下:#include<bits/stdc++.h>using namespace std;int f[25];int main(){ int n; cin >> n; f[0]=1,f[1]=1; for(int i = 2; i <= n; i++)f[i]=f[i-1]+f[i-2];
2021-06-25 14:05:46
253
原创 OpenJudge -7625:三角形最佳路径问题
原题:http://noi.openjudge.cn/ch0206/7625/这道题是一道十分经典的动态规划问题,也被今年的等级考试四级征用了。这道题有两种方案,第一种是从上到下遍历,另一种是从下到上遍历。本人认为应该是第二种方案更为简单易懂,直接输出dp[1][1]就可以了。贴代码:#include<bits/stdc++.h>using namespace std;int n,a[110][110],dp[110][110];int main(){ cin >>
2021-06-21 20:28:55
274
原创 OpenJudge -8780:拦截导弹题解
原题:http://noi.openjudge.cn/ch0206/8780/这道题其实就是一个非常典型的最长上升子序列,只不过是倒过来的而已。你也可以使用最长下降子序列来进行求解。下面是蒟蒻的代码:#include<bits/stdc++.h>using namespace std;int n,a[20],sum[20],ans;//数组长度定义长一些,好习惯。int main(){ cin >> n; for(int i = n; i >= 1;
2021-06-19 14:54:13
467
原创 青蛙爬井
关于小青蛙爬井的故事,你应该早就听过了:井深10尺,小青蛙从井底向上爬,每个白天向上爬3尺,每天晚上又滑下来2尺,然后问你第几天它能爬上来。答案是第8天。现在,那支著名的小青蛙又回来了,它现在每个白天已经可以向上爬a尺了,当然,晚上还是要下滑b尺的。如果告诉你井深n尺,请计算一下,它第几天可以爬上来。#include<bits/stdc++.h>using namespace std;int main(){ long long a,b,h,n = 0,i = 1; while(1)
2020-10-01 11:09:52
2403
原创 大写字母的个数
大写字母的个数描述输入一行字符串,统计字符串当中大写字母的个数。输入共1行,一行字符串,字符串当中只包含英文字母。输出字符串当中大写英文字母的个数。输入样例 1AAAbbbcccDDD输出样例 16#include<bits/stdc++.h>using namespace std;int main(){string a;getline(cin,a);...
2020-03-07 21:24:38
534
请问本题为什么小数据也过不了?
2021-12-11
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅
2