![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
oj
小兔崽崽!
我还年轻!!!
展开
-
题目 1815: [蓝桥杯][2014年第五届真题]排列序数(next_permutation())
思路:直接用全排列 next_permutation() 函数,在函数加上一个count1做统计。#include <bits/stdc++.h>using namespace std;int main(){ string s,x; cin>>s; x = s; int count1 = 0; sort(s.begin(),s.end()); do{ while(s==x){ cout<..原创 2020-07-22 09:03:41 · 133 阅读 · 0 评论 -
传送门
思路:这道题可以用并查集来做,首先按时间先排序。然后循环遍历,看A和B两个城市是否联通,如果不连通就Union(A,B)。#include <bits/stdc++.h>using namespace std;int pre[100010];int n,m;void init(){ for(int i=0;i<m;i++){ pre[i] = i; }}struct node{ int a,b; int time;};bo.原创 2021-04-12 21:43:07 · 187 阅读 · 0 评论 -
[蓝桥杯][2013年第四届真题]买不到的数目(数论)
思路:我直接用一个数组去遍历一遍,首先就初始化 x[a] =1,x[b] = 1,然后一个循环将 只要 x[i]==1 ,那么就将x[i+a] 和 x[i+b]初始化为1.最后去找最后一个为0的数组下标。#include <bits/stdc++.h>using namespace std;int x[10000000];int main(){ int a,b; cin>>a>>b; memset(x,0,sizeof(x)); ..原创 2020-07-21 15:33:39 · 130 阅读 · 0 评论 -
[蓝桥杯][2017年第八届真题]青蛙跳杯子(BFS)
思路:这道题就用bfs去搜索就行,要注意的就是用一个map<string,int>mp去记录每种情况,进而达到去重的目的。#include <bits/stdc++.h>using namespace std;string s1,s2;int ans,sx;int dx[6] = {1,2,3,-1,-2,-3};map<string, int>mp; //判断该序列是否出现过,避免重复搜索struct node{ int x,step; ..原创 2020-08-01 17:00:02 · 271 阅读 · 0 评论 -
[蓝桥杯][2014年第五届真题]分糖果 (模拟 暴力)
水题,直接暴力的去模拟就过了。日常划水系列#include <bits/stdc++.h>using namespace std;int a[110];int main(){ int n;cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; } int flag ,cnt = 0; while(1){ flag = 0; int temp .原创 2020-08-08 10:21:32 · 195 阅读 · 0 评论 -
[蓝桥杯][算法提高VIP]大数加法
思路:以前大一的时候写过大数a+b,只不过那个时候写的比较复杂的感觉,现在是用字符串模拟,直接字符串a和b中每一位反过来存数组中,然后直接每一位相加,如果加的和大于10,下一位加1,本位求余10,最后从后往前遍历一遍ans数组找到最高位的位置,然后再将答案输出即可。#include<bits/stdc++.h>using namespace std;string a,b;int x[1010],y[1010],ans[1010];int main(){ cin>>.原创 2020-08-09 11:00:10 · 200 阅读 · 3 评论 -
[蓝桥杯][历届试题]回文数字(水题)
水题,直接模拟出来就行。#include <bits/stdc++.h>using namespace std;bool huiwen(int x){ int x1 = 0,x2 = x; while(x2){ x1 = x1*10+x2%10; x2 = x2/10; } if(x1==x) return true; return false;}int main(){ int n; cin>&..原创 2020-08-08 10:48:50 · 213 阅读 · 0 评论 -
小明的作业(蓝桥杯)
#include <bits/stdc++.h>using namespace std;int main(){ int cnt_w = 0, cnt_e = 0; string s="iawaswapwauawhawdwafwanbiopwanivgbikvblvbwawawawvolyuvgbololvolgbyolgyowagbolgawgboplwawaolgyolwaogblwaygbowawagwabwayawopwawagyowabwaowapjwapc..原创 2021-04-12 20:18:13 · 188 阅读 · 0 评论 -
[蓝桥杯][算法提高VIP]素数求和 (筛选法求素数)
思路:这个题用暴力去做肯定是会超时的,所以要换一种方法求小于等于n的素数和,这道题用的是筛选法求素数。用筛法求素数的基本思想是:把从1开始的、某一范围内的正整数从小到大顺序排列, 1不是素数,首先把它筛掉。剩下的数中选择最小的数是素数,然后去掉它的倍数。依次类推,直到筛子为空时结束。如有:1 2 3 4 5 6 7 8 9 1011 12 13 14 15 16 17 18 19 2021 22 23 24 25 26 27 28 29 301不是素数,去掉。剩下的数中2最小,是素数,去掉2的倍.原创 2020-07-21 10:12:30 · 288 阅读 · 0 评论 -
[蓝桥杯][2019年第十届真题]旋转 (水题)
思路:水题,用一个二维数组存下来,然后按照要求输出一下就行。#include <bits/stdc++.h>using namespace std;int main(){ int n,m; cin>>n>>m; int a[n+10][m+10]; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; ..原创 2020-07-19 16:57:04 · 363 阅读 · 0 评论 -
[蓝桥杯][2019年第十届真题]等差数列
思路:就是对它先排序找出最小的差,那就是等差数列差,要注意的一点就是要判断一下它的差是不是0,原创 2020-07-19 16:19:32 · 1261 阅读 · 1 评论 -
[蓝桥杯][2019年第十届真题] 特别数的和 (暴力)
思路:直接暴力循环一遍去寻找符合条件的数相加即可#include <bits/stdc++.h>using namespace std;int main(){ int n; cin>>n; int sum = 0; for(int i=1;i<=n;i++){ int x = i; int flag = 0; while(x){ int s = x%10; .原创 2020-07-19 15:42:24 · 146 阅读 · 0 评论 -
[蓝桥杯][2013年第四届真题]错误票据(水题)
#include <bits/stdc++.h>using namespace std;int a[1010];int main(){ ios::sync_with_stdio(); int n; cin>>n; int pos = 0; while(n--){ while(cin>>a[pos++]){ if(cin.get()=='\n') break; .原创 2020-09-28 20:23:52 · 154 阅读 · 0 评论 -
[蓝桥杯][2014年第五届真题]重复模式(暴力 substr函数 find函数)
<思路> 第一种写法就是用循环去找,也就是俗称的暴力解法。另外一种就是用string类型中的find函数和substr函数去找。方法1:#include <bits/stdc++.h>using namespace std;int main(){ string s; cin>>s; int len1 = s.length(); int cnt =0,ans=0; for(int i=0;i<len1;i++){ .原创 2020-07-22 09:34:06 · 176 阅读 · 0 评论 -
[蓝桥杯][算法提高VIP]最长单词
思路:这个题就直接遍历一遍找一下最长的就好#include <bits/stdc++.h>using namespace std;int main(){ string s; getline(cin,s); int cnt = 0,max1 = 0; int x= 0,e=0; for(int i=0;i<s.length();i++){ if(s[i]==' '||i==s.length(.原创 2020-07-20 17:30:20 · 156 阅读 · 0 评论 -
C语言判断闰年
如果一个年份是闰年要满足一下条件:1、能被4整除,但不能被100整除;2、能被400整除; 所以判断闰年的条件为(year%4==0&&year%100!=0)||year%400==0#include<bits/stdc++.h>using namespace std;int main(){ int year ; cin>>year; if((year%4==0&&year%100!=0)||year%400==原创 2020-07-26 10:41:43 · 578 阅读 · 0 评论 -
题目 1084: 用筛法求之N内的素数。
就是用筛选法求出素数即可。#include <bits/stdc++.h>using namespace std;int prime[1000000];void buildprime(int n){ for(int i=2;i<=sqrt(n);i++){ if(prime[i]==0){ for(int j=i*i;j<=n;j+=i){ prime[j]=1; }..原创 2020-07-21 15:48:46 · 408 阅读 · 0 评论 -
[蓝桥杯][2014年第五届真题]Log大侠
在程序中可以直接使用log函数,题目要求要向下取整,所以我们直接把log2(a[i])的转化成int类型就可以做到向下取整了。‘#include <bits/stdc++.h>using namespace std;int main(){ int n,m; cin>>n>>m; int a[n+10]; for(int i=1;i<=n;i++){ cin>>a[i]; } while..原创 2020-07-22 09:54:10 · 136 阅读 · 0 评论 -
[蓝桥杯][2018年第九届真题]次数差
#include <bits/stdc++.h>using namespace std;int cnt[1001];int main(){ string s; cin>>s; int max1 = -1,min1 = 1001; for(int i=0;i<s.length();i++){ for(int j=0;j<=s.length();j++){ if(s[i]==s[j]){ .原创 2020-07-21 11:07:56 · 293 阅读 · 0 评论 -
[蓝桥杯][历届试题]蚂蚁感冒 (思维)
思路:这道题没有必要去用模拟写,其实最后的结果和第一只感冒的蚂蚁的头的方向没关系。只有以下两种情况其它的蚂蚁会感冒:1.在第一只蚂蚁的右边,并且向左走。2.在第一只蚂蚁的左边,并且向右走。今日份水题=-=#include <bits/stdc++.h>using namespace std;int a[55];int main(){ ios::sync_with_stdio(false); int n; cin>>n; for(int i.原创 2020-08-09 09:39:49 · 162 阅读 · 0 评论 -
[蓝桥杯][历届试题]翻硬币 (贪心)
思路:因为每次都要翻相邻的两个,所以最少的情况就是从头开始找两次两个字符串不同的位置的差值,就是要翻的次数。#include <bits/stdc++.h>using namespace std;int main(){ //ios::sync_with_stdio(false); string a,b; cin>>a>>b; int len1 = a.length(); int flag = 0,ans = 0; fo.原创 2020-08-09 09:55:39 · 985 阅读 · 0 评论 -
鸽者文明的三体问题 (数学)
思路:题目的太概意思就是给你很多个三角形区域,平面中的点满足在一个三角形区域就被覆盖了一次,如果覆盖了奇数次就存在引力,否则不存在。那么这道题的关键就是去判断点(xqi,yqi)是否在三角形区域内。判断p点是否在三角形内部:用面积法去判定如果在三角形内部就必须满足 SABC = S ABP + SACP+SBCP;因为这道题目给出的是三个点的坐标那么三角形的面积就用向量叉乘/2来计算。ABC的面积 = 向量AC叉乘向量AB;#include <bits/stdc++.h>..原创 2020-11-11 20:56:31 · 280 阅读 · 0 评论 -
Mathematical Practice (快速幂)
思路:该题就是从一个大小为 的集合中,有顺序地取 次子集,求这些子集两两没有交集的方案数。首先可以发现这个n和m的范围还是蛮大的,直接暴力肯定不行,那么就用快速幂来算我们要的结果。#include <bits/stdc++.h>using namespace std;int mod = 998244353;int ans;int fast_power(long long base,long long power,long long mod){ long long re..原创 2020-11-17 19:03:41 · 383 阅读 · 2 评论 -
轮到谁了? mod
思路:这就是一个斐波那契数列,只不过每次循环求f[i]的时候都要求余m。f[i]就是第i个月兔子的数量。而这个月最后一队兔子的编号就是(f[n]+m-1)%m。#include <bits/stdc++.h>using namespace std;int f[1005];int main(){ int t; cin>>t; while(t--){ int n,m; cin>>n>>m; f[1] .原创 2020-11-11 19:35:47 · 90 阅读 · 0 评论 -
管管的幸运数字(线性筛)
思路:这个题暴力也可以过,而我是先筛选出素数来,然后对于每次询问再去判定n是不是素数,如果不是再去找比它小和比它大的素数。最终找到最近的那个。#include <bits/stdc++.h>using namespace std;int prime[100010];void is_prime(int x){ for(int i=2;i<=sqrt(x);i++){ if(prime[i]==0){ for(int j=i*i;j&l.原创 2020-11-10 20:54:07 · 169 阅读 · 0 评论 -
两点距离
思路:就只有三种情况。1.x == y时,这个时候距离为0;2.gcd(x,y) = 1 时,这个时候就已经满足x到y的最短距离了3.剩下的最短距离都是2,x移动到y不一定是直接过去,可以中间找一个点,x先去1,然后从1到y这样距离就是2.#include <bits/stdc++.h>using namespace std;int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); .原创 2020-11-10 20:47:49 · 150 阅读 · 0 评论 -
松哥的困惑 STL
思路:直接先找字符串中有没有三个大写的字符,三个大写的字符就满足了名字是三个字,然后再用string类中的find方法找子串,如果存在就返回第一个找到的子串的位置,否则返回-1.#include <bits/stdc++.h>using namespace std;int n;int main(){ while(cin>>n){ while(n--){ string s; cin>>s; .原创 2020-11-10 19:05:02 · 163 阅读 · 0 评论 -
胥哥的DOTA 暴力
思路:首先可以发现数据的范围是比较小的,所以我们可以采取暴力的方法,直接遍历直线上每个位置求出伤害并找到最小的值。#include <bits/stdc++.h>using namespace std;int n,m;struct node{ int index; int x;};int main(){ while(cin>>n>>m){ node no[n+10]; for(int i=0;i<.原创 2020-11-10 18:49:48 · 116 阅读 · 0 评论 -
闪闪发光 (思维,STL)
思路:2^1 2 ^1 两个数加起来可以变成 2 ^2 ,所以只需要遍历一遍,将两个相同的数遍成一个加1的数,最后统计剩下的数就是最少的举重次数。 下面就用两种方法来写这道题。`#include <bits/stdc++.h>using namespace std;int cnt[2000050];int main(){ int n; while(cin>>n){ memset(cnt,0,sizeof(cnt)); i.原创 2020-11-05 19:44:54 · 117 阅读 · 0 评论 -
帮我求算一下斐波那契数吧(矩阵快速幂)
思路:这道题的n非常大,如果直接暴力写的话肯定会超时,所以这道题要用到矩阵快速幂的知识。对于斐波那契数列,可以用上述矩阵来求Fn的值。#include <bits/stdc++.h>using namespace std;const int num = 2;const long long mod = 1000000007;struct mat { long long m[num][num];}; mat I{ //定义了一个单位矩阵。 1,0, 0,1..原创 2020-08-05 09:27:33 · 116 阅读 · 0 评论 -
Maxim and Discounts(贪心)
Maxim and Discounts描述Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the c原创 2020-07-15 09:54:50 · 190 阅读 · 0 评论 -
均分纸牌(贪心)
题目描述有 N 堆纸牌,编号分别为 1,2,…, N。每堆上有若干张,但纸牌总数必为 N 的倍数。可以在任一堆上取若于张纸牌,然后移动。 移牌规则为:在编号为 1 堆上取的纸牌,只能移到编号为 2 的堆上;在编号为 N 的堆上取的纸牌,只能移到编号为 N-1 的堆上;其他堆上取的纸牌,可以移到相邻左边或右边的堆上。 现在要求找出一种移动方法,用最少的移动次数使每堆上纸牌数都一样多。 ...原创 2020-02-28 21:20:13 · 501 阅读 · 0 评论 -
通信系统(并查集)
题目描述某市计划建设一个通信系统。按照规划,这个系统包含若干端点,这些端点由通信线缆链接。消息可以在任何一个端点产生,并且只能通过线缆传送。每个端点接收消息后会将消息传送到与其相连的端点,除了那个消息发送过来的端点。如果某个端点是产生消息的端点,那么消息将被传送到与其相连的每一个端点。为了提高传送效率和节约资源,要求当消息在某个端点生成后,其余各个端点均能接收到消息,并且每个端点均不会重复收到...原创 2020-02-03 22:31:59 · 440 阅读 · 5 评论 -
1700: 合根植物(并查集)
题目描述w星球的一个种植园,被分成 m * n 个小格子(东西方向m行,南北方向n列)。每个格子里种了一株合根植物。这种植物有个特点,它的根可能会沿着南北或东西方向伸展,从而与另一个格子的植物合成为一体。如果我们告诉你哪些小格子间出现了连根现象,你能说出这个园中一共有多少株合根植物吗?输入第一行,两个整数m,n,用空格分开,表示格子的行数、列数(1<m,n<1000)。接下...原创 2020-01-31 17:15:59 · 93 阅读 · 0 评论 -
1073: 第八章:我们终究差了一厘米(树的遍历)
[提交][状态][讨论版]题目描述几年后,林静和陈孝正都出现在郑微面前,而工作后的郑微也纠葛在工作、感情甚至阴谋之中。面对林静和陈孝正,郑薇该如何选择。。。选择总是那么困难,每一个结点都有两种选择,这个不是“二叉树”吗?现在有一个二叉树,我们已知它的先序遍历的结果和中序遍历的结果。请你给出它的后序遍历结果。输入输入有多组数据,每组的第一行是一个n,表示这棵二叉树有n个结点然后是两行,...原创 2019-11-19 20:50:12 · 102 阅读 · 0 评论 -
Out of Hay
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 21288 Accepted: 8417DescriptionThe cows have run out of hay, a horrible event that must be remedied immediately. Bessie intends to visit ...原创 2019-11-18 21:15:59 · 105 阅读 · 0 评论 -
Candies(二分,模拟)
After passing a test, Vasya got himself a box of nn candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided ...原创 2019-11-04 23:29:34 · 518 阅读 · 0 评论 -
The Way to Home(动态规划,模拟)
A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the po...原创 2019-10-29 22:37:30 · 1108 阅读 · 0 评论 -
1192: 货币系统(背包)
[提交][状态][讨论版]题目描述给你一个n种面值的货币系统,求组成面值为m的货币有多少种方案。样例:设n=3,m=10,要求输入和输出的格式如下:输入第一行两个整数n,m(m<=5000)以下n行,每行一个整数,第i+1行为第i种货币的面值输出一个整数,为方案数样例输入3 10125样例输出10提示来源动态规划-背包问题#include<bits/...原创 2019-10-14 00:14:35 · 141 阅读 · 0 评论 -
1314: 珍惜现在,感恩生活(多重背包)
急!灾区的食物依然短缺!为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买。请问:你用有限的资金最多能采购多少公斤粮食呢?后记:人生是一个充满了变数的生命过程,天灾、人祸、病痛是我们生命历程中不可预知的威胁。月有阴晴圆缺,人有旦夕祸福,未来对于我们而言是一个未知数。那么,我们...原创 2019-10-11 20:37:40 · 126 阅读 · 0 评论