![](https://img-blog.csdnimg.cn/20191004220044617.jpg?x-oss-process=image/resize,m_fixed,h_224,w_224)
洛谷
刷的洛谷题目
戎码关山
你在炫耀诗和远方,父母却尚在苟且
展开
-
数据结构--线性表
P3613 【深基15.例2】寄包柜这道题如果使用数组a[100000][100000]一定会爆内存,TLE所以只能使用动态储存容器,vector或者map这里储存的是一个三维的数据:分别是 柜子 格子 和 格子里的物品我们用柜子*100000+格子来实现降维#include<bits/stdc++.h>using namespace std;typedef long long ll;ll n,q,ans,l,r;map<ll,int> a;int main()原创 2021-06-01 17:47:58 · 154 阅读 · 0 评论 -
二分查找与二分答案
P1102 A-B 数对1这一题将A-B=C转换成A-C=B,首先将A数组每个元素出现的次数统计起来,用map映射,最后将A数组每次减一个C,再将A数组扫一遍,将所有映射的次数和加起来就是答案这种做法真的是很巧妙,但是没有用到二分#include<bits/stdc++.h>using namespace std;typedef long long ll;map<ll,ll> m;ll a[200055];int main(){ int n,c;原创 2021-06-01 10:59:23 · 174 阅读 · 0 评论 -
洛谷贪心题集
排队接水有一个巧妙的存数据方式来输出排序之后编号的顺序(针对快排懒得用结构体的同学)因为n<=1000所以给每个ti都*1001,在加上当前序号可以保证排序的时候序号不干扰排序又可以方便输出序号(只需mod1001输出序号,/1001 输出时间)#include<bits/stdc++.h>using namespace std;long long t[2000];int main(){ int n; double sum = 0; //这里sum必须原创 2021-06-01 07:51:50 · 227 阅读 · 0 评论 -
高精度加法和乘法
高精乘#include<bits/stdc++.h>using namespace std;string Add_(string s1,string s2){ string str; int len1 = s1.length(); int len2 = s2.length(); if(len1 < len2) { for(int i = 1;i <= len2-len1;i++) s1 = "0"原创 2021-05-05 12:27:10 · 133 阅读 · 0 评论 -
P1319 压缩技术
1、不要一遇到矩阵问题就使用二维数组,这个题使用一维数组更加方便快捷2、持续输入且不知道输入数据的个数,使用while(cin >> a)#include <bits/stdc++.h>using namespace std;bool is = 0;int main(int argc, char const *argv[]){ int n;cin >> n; int a[n*n+5]; int t;int x = 1; while(cin >&g原创 2020-07-15 07:04:28 · 816 阅读 · 0 评论 -
P5732 【深基5.习7】杨辉三角
题目描述给出 n(n\le20)n(n≤20),输出杨辉三角的前 nn 行。如果你不知道什么是杨辉三角,可以观察样例找找规律。1、声明数组填满前30行2、按行输出#include <bits/stdc++.h>using namespace std;int a[30][30];int main(int argc, char const *argv[]){ a[1][1] = a[2][1] = a[2][2] = 1; for(int i = 3;i < 25;i++原创 2020-07-14 18:51:02 · 845 阅读 · 0 评论 -
P5731 【深基5.习6】蛇形方阵
题目描述给出一个不大于 9 的正整数 nn,输出 n\times nn×n 的蛇形方阵。从左上角填上 1 开始,顺时针方向依次填入数字,如同样例所示。注意每个数字有都会占用 3 个字符,前面使用空格补齐。使用5个while循环模拟顺时针的旋转#include <bits/stdc++.h>using namespace std;int a[90][90];int main(int argc, char const *argv[]){ int n;cin >> n;原创 2020-07-14 18:37:57 · 1647 阅读 · 0 评论 -
P2911 [USACO08OCT]Bovine Bones G
利用桶容器来记录每个数的频率,再从小往大枚举,可以避开相等的大下标#include <bits/stdc++.h>using namespace std;int a[100];int main(int argc, char const *argv[]){ int n,m,k;int t = 0,ans = 0;; cin >> n >> m >> k; for(int i = 1;i <= n;i++) for(int j = 1;j原创 2020-07-14 18:16:22 · 591 阅读 · 0 评论 -
P1614 爱与愁的心痛
我最开始的错误在于没有将ans设置为一个极大值,影响了ans的更新。#include <bits/stdc++.h>using namespace std;int a[3050];int c;int main(int argc, char const *argv[]){ int ans = 99999; int n,m; cin >> n >> m; for(int i = 1;i <= n;i++)cin >> a[i];原创 2020-07-14 15:40:04 · 459 阅读 · 0 评论 -
P2141 珠心算测验
1、首先进行排序,保证不重不漏2、使用数组进行去重#include <bits/stdc++.h>using namespace std;int n;int a[110];bool is[10005];int main(int argc, char const *argv[]){ cin >> n; int c = 0; for(int i = 1;i <= n;i++)cin >> a[i]; sort(a+1,a+n+1); for(i原创 2020-07-14 15:28:07 · 389 阅读 · 1 评论 -
P5727 【深基5.例3】冰雹猜想
#include <bits/stdc++.h>using namespace std;int a[10000];int main(int argc, char const *argv[]){ int n;cin >> n;int i = 1; while(n!=1) { a[i] = n;i++; if(n%2)n = 3*n +1; else n/=2; }a[i] = 1; for(int j = i;j > 0;j--)cout <&原创 2020-07-06 09:52:35 · 430 阅读 · 0 评论 -
P4956 [COCI2017-2018#6] Davor
最开始的代码:#include <bits/stdc++.h>using namespace std;int main(int argc, char const *argv[]){ int n;cin >> n; int a[n];double sum = 0.0; for(int i = 0;i < n;i++) cin >> a[i]; sort(a,a+n); for(int i = 1;i < n-1;i++) sum+=a[原创 2020-07-05 23:24:50 · 290 阅读 · 0 评论 -
P1075 质因数分解
我刚开始想排查出最大的质因数,可是发现超时了;#include <bits/stdc++.h>using namespace std;bool is(int n){ for(int i = 2;i <= sqrt(n) ;i++) if(n%i==0)return 0; return 1;}int main(int argc, char const *argv[]){ int n;cin >> n; for(int i = n-1;i>0;i--原创 2020-07-05 22:25:39 · 200 阅读 · 0 评论 -
P5724 【深基4.习5】求极差
#include <bits/stdc++.h>using namespace std;int main(int argc, char const *argv[]){ int n;cin >> n; int a[n]; for(int i = 0;i < n;i++)cin>>a[i]; sort(a,a+n); cout << a[n-1]-a[0]; return 0;}还有就是不断更新最大值最小值,有点麻烦,不推荐...原创 2020-07-05 22:07:49 · 430 阅读 · 0 评论 -
P5723 【深基4.例13】质数口袋
#include <bits/stdc++.h>using namespace std;bool is(int n){ for(int i = 2;i <= sqrt(n) ;i++) if(n%i==0)return 0; return 1;}int main(int argc, char const *argv[]){ int l;cin >> l; long long sum = 0,n = 0; if(l < 2) { cout &原创 2020-07-05 21:16:50 · 742 阅读 · 0 评论 -
P5721 【深基4.例6】数字直角三角形 题解
我的代码#include <iostream>using namespace std;int i=1;int main(int argc, char const *argv[]){ int n;cin >> n; while(n) { for(int j = 1;j <= n;j++) { if(i < 10)cout << '0'; cout << i; i++; } cout <<原创 2020-07-05 18:58:31 · 512 阅读 · 0 评论 -
P5719 【深基4.例3】分类平均
#include <iostream>#include <iomanip>using namespace std;int main(int argc, char const *argv[]){ int n,k,a=0,b=0,ai=0,bi=0; cin >> n >> k; for(int i = 1;i <= n;i++) { if(i%k==0)a+=i,ai++; else b+=i,bi++; } double ax原创 2020-07-05 18:32:27 · 432 阅读 · 0 评论 -
P2670扫雷游戏
链接对于这个题,我原来的思路是判断一个地雷周围一圈是否数组越界,然后统计它们的数量#include<iostream>using namespace std;char mine[200][200];int map[200][200];int n,m;int main(){ cin >> n >> m; for(int i = 0;i < n;i++) for(int j = 0;j < m;j++)原创 2020-05-22 08:07:39 · 267 阅读 · 0 评论 -
乒乓球的十一分制和二十一分制
刚开始的那种输入一行信息做判断的方法需要进行掌握#include<iostream>using namespace std;int sign[1000000];int w,l;int main(){ char s; for(int i = 1;cin>>s&&s!='E';i++)//E可能出现在字符串中间或者末尾,也可能之前会有换行 { if(s == 'W')sign[i]=1;//将字符信息转化为容易处理的数字原创 2020-05-19 09:15:38 · 1279 阅读 · 0 评论 -
P1426 小鱼会有危险吗
主要是需要进行判断,注意特判s<x的情况#include<iostream>using namespace std;double v = 7.0;double t1,t2;double dis;int main(){ double s,x;cin >>s >> x; if(s<x) { cout...原创 2020-02-29 09:20:03 · 320 阅读 · 0 评论 -
P2089 烤鸡
这道题使用暴力枚举就可以了,因为每个循环分量是常数复杂度#include<iostream>using namespace std;int count;int arr[5000][11];int main(){ int n; cin >> n; if(n<10||n > 30) { cout <...原创 2020-02-29 08:05:15 · 314 阅读 · 0 评论 -
P1579 哥德巴赫猜想(升级版)
不用枚举第三个变量,因为它和前两个变量之和为定值,不需要自己增加复杂度出错是因为粗心,没有发现循环中使用的是2009而不是n#include<iostream>using namespace std;bool isprime(int n){ if(n==1)return 0; for(int i = 2;i*i <= n;i++) ...原创 2020-02-28 21:51:39 · 169 阅读 · 0 评论 -
P1618 三连击(升级版)
这个题枚举第一个数,后面两个数根据比例关系进行计算,然后比对每一位的所有书加起来是不是45,乘起来是不是9!=362880#include<iostream>using namespace std;int a,b,c;int main(){ cin >> a >> b >> c; for(int i = 123;i <...原创 2020-02-28 21:49:50 · 360 阅读 · 0 评论 -
P1478 陶陶摘苹果(升级版)
这个题比较复杂,因为可能就按照符合条件逐个选取,但是有一种情况,就是符合条件的苹果有很多,你本可以选择在最小力气的成本下摘取最多的苹果。...原创 2020-02-28 20:36:23 · 203 阅读 · 0 评论 -
P5722 【深基4.例11】数列求和||||||accumulate(头指针,尾指针,初始值)函数
https://www.luogu.com.cn/problem/P5722我直接累加输出了#include<iostream>using namespace std;int tot;int main(){ int n;cin >> n; for(int i = 1;i <= n;i++) tot+=i; co...原创 2020-02-16 09:37:10 · 268 阅读 · 0 评论 -
P2788 数学1(math1)- 加减算式
https://www.luogu.com.cn/problem/P2788#include<iostream>using namespace std;long long tot;int tem = 0,f = 1;int main(){ string a; cin >> a; int len = a.size(); for(i...原创 2020-02-15 22:55:14 · 409 阅读 · 0 评论 -
P1150 Peter的烟
https://www.luogu.com.cn/problem/P1150#include<iostream>using namespace std;int tot;int main(){ int n,k; cin >> n >> k; if(n <= k) tot = n; else ...原创 2020-02-15 22:28:51 · 261 阅读 · 0 评论 -
P1321 单词覆盖还原
https://www.luogu.com.cn/problem/P1321这道题为我进行残缺字符串的查找提供了一个新的思路可以使用||运算来匹配残缺字符串!#include<iostream>using namespace std;int b,g;int main(){ string a; cin >> a; int len =...原创 2020-02-15 22:09:48 · 447 阅读 · 0 评论 -
P1149 火柴棒等式 (DFS)
https://www.luogu.com.cn/problem/P1149起初以为这个题需要dfs,但是其实只需要一个2000x2000的循环就可以枚举出全部答案。忘记了0需要特判一下#include<iostream>using namespace std;int tot,n;int s[11] = {6,2,5,5,4,5,6,3,7,6,0};int mat...原创 2020-02-15 21:38:26 · 301 阅读 · 0 评论 -
P1036 选数 (DFS大法好!)
https://www.luogu.com.cn/problem/P1036这道题要是用dfs算法,这是我写的第一道dfs算法题,真正理解了它的意思。#include<iostream>using namespace std;int tot,a[25];int n,k;bool prime(int n){ for(int i = 2;i*i <= ...原创 2020-02-15 20:47:41 · 359 阅读 · 0 评论 -
P1028 数的计算
https://www.luogu.com.cn/problem/P1028这不是一个暴力题,如果暴力来做会TLE,所以需要找出规律递归#include<iostream>#include<cmath>using namespace std;int f[1005];int shu(int n){ return floor(n*1.0/2);}...原创 2020-02-15 18:24:20 · 161 阅读 · 0 评论 -
P1308 统计单词数
https://www.luogu.com.cn/problem/P1308第一次知道原来char数组可以开这么大是gets函数的头文件忘记了可以是字符串中某一个单词含有第一个单词,这也算进了个数,需要判断一下左右是否有空格中含有isupper()和toupper等函数终于AC了!#include<iostream>#include<cctype>#...原创 2020-02-15 17:04:50 · 369 阅读 · 0 评论 -
P1055 ISBN号码
https://www.luogu.com.cn/problem/P1055最开始在mod11为10时,最后一位识别码为X,这一点没有注意到,导致WA,修改后就满分#include<iostream>using namespace std;int m;int i_ = 1;int main(){ string a="0-670-82162-4"; c...原创 2020-02-15 15:46:12 · 147 阅读 · 1 评论 -
P1980 计数问题(注意千万在循环中不能改变i的值)
暴力枚举比较每一位的数值最初我以为是复杂度太高了呢#include<iostream>using namespace std;long long tot;int main(){ int n,x; cin >> n >> x; for(int i = 1;i <= n;i++) { ...原创 2020-02-15 11:37:46 · 203 阅读 · 0 评论 -
P1008 三连击 巧妙的循环输出
https://www.luogu.com.cn/problem/P1008最开始需要确定a的浮动区间,因为a,b,c无论如何都存在1:2:3的比例,最小值当然是123,但是我在最初确定最大值的视乎以为是321,但是实际上却是327,因此为了方便就将其设置为333.如果三个数的每一位数相加等于1+2+。。。+9,相乘等于1*2。。。*9,这样就可以唯一确定数字不重不漏。#include&l...原创 2020-02-15 10:53:43 · 304 阅读 · 0 评论 -
P1909 买铅笔
总是有WA的点#include<iostream>#include<cmath>using namespace std;long long n,a[7],b[4],m = 10000000;int main(){ cin >> n; for(int i = 1;i <= 6;i++) cin >...原创 2020-02-15 10:13:16 · 293 阅读 · 0 评论 -
P6056 [加油武汉]SIR 模型
https://www.luogu.com.cn/problem/P6056这个题太麻烦了不知道出题人希望我们结算的顺序是什么,反正只过了三个点。#include<iostream>#include<cmath>using namespace std;int main(){ long long s,f,r=0,n,tot;double a,b;...原创 2020-02-15 07:59:24 · 613 阅读 · 0 评论 -
P1304 哥德巴赫猜想
这个题还是值得纪念 的,因为之前没有过,很久以前做的#include<iostream>using namespace std;bool prime(int n){ if(n == 2) //0和1不是质数 return 1; for(int i = 2;i*i <= n;i++) if(n%i == 0...原创 2020-02-14 23:17:22 · 791 阅读 · 0 评论 -
P1876 开灯
这道题明显不知原理,所以只能数组硬算,但是只过了一个点,其中还有一个点MLE(内存超标)人生第一次#include<iostream>#include<cstring>using namespace std;int main(){ int n;cin >> n; int *a = new int[n+1]; memset(a,...原创 2020-02-14 22:57:03 · 259 阅读 · 0 评论 -
P1838 三子棋I
这道题终于AC了代码修改比较久:#include<iostream>using namespace std;bool xiaoa[15];bool uim[15];bool win(bool a[]){ if((a[1]&a[2]&a[3])||(a[3]&a[6]&a[9])||(a[1]&a[4]&a[7])...原创 2020-02-14 22:30:55 · 592 阅读 · 2 评论