蓝桥杯最终冲刺(冲刺Day2)
1.含2天数(20年国赛——3月16日)
思路:这一天的年月日中只要有一个2即符合条件
#include <iostream>
using namespace std;bool isyear(int x)
{return (x % 400 == 0 || x % 4 == 0 && x % 100 != 0);
}bool check(int n)
{while(n){if(n % 10 == 2)return true;n /= 10;}return false;
}int main()
{int cnt = 0;for(int i = 1900; i <= 9999; i ++)//枚举年份{if(check(i)) //年份包含2{if(isyear(i)) cnt += 366;else cnt += 365;}else{if(isyear(i))cnt += 180;//每个月含2天数 + 2月 + 12月elsecnt += 179;}}cout << cnt << endl;return 0;
}
2.蓝桥幼儿园(3月21日)
OP 判定
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+10;
int fa[MAXN];
void init(int n){for(int i=1;i<=n;i++){fa[i] = i;}
}
int find(int x){return x==fa[x] ? fa[x] : (fa[x]=find(fa[x]));
}
void merge(int x,int y){int fx = find(x);int fy = find(y);if(fx!=fy){fa[fx] = fy; }
}
int main()
{int n,m;cin >> n >> m;init(n);for(int i=0;i<m;i++){int t,x,y;cin >> t >> x >> y;if(t==1){merge(x,y);}else{if(find(x)==find(y)){cout << "YES" << endl;}else{cout << "NO" << endl;}}}}
3.七星填数(16年国赛——3月27日)
暴力就完事了
#include <iostream>
#include <algorithm>
using namespace std;
int a[11]={1,2,3,4,5,7,8,9,10,12,13};
int main()
{do{int sum=a[0]+a[1]+a[2]+a[3];if(6+a[2]+a[5]+11==sum&&6+a[1]+a[4]+14==sum&&a[0]+a[4]+a[6]+a[9]==sum&&a[3]+a[5]+a[7]+a[10]==sum&&14+a[6]+a[8]+a[10]==sum&&a[9]+a[8]+a[7]+11==sum){printf("%d %d %d %d",a[0],a[1],a[2],a[3]);}}while(next_permutation(a,a+11));return 0;
}
4.日志统计(18年省赛——3月13日)
该题为二刷题,解题思路与第一次做一致,所以就直接上代码了
#include<cstdio>
#include<algorithm>
using namespace std;
int n,d,k;
int nowlike[100005];
struct node{int ts;int id;
};
node arr[100005];
bool ishot[100005];
bool cmp(node x,node y)
{return x.ts<y.ts;
}
int main()
{scanf("%d%d%d",&n,&d,&k);for(int i=1;i<=n;i++)scanf("%d%d",&arr[i].ts,&arr[i].id);sort(arr+1,arr+1+n,cmp);int l = 1;for(int i=1;i<=n;i++){ nowlike[arr[i].id]++;while(arr[i].ts >= arr[l].ts + d) nowlike[arr[l++].id]--;if(nowlike[arr[i].id]>=k) ishot[arr[i].id] = true;}for(int i=0;i<=100005;i++)if(ishot[i])printf("%d\n",i);return 0;
}
5.子串分值
#include <iostream>
#include <vector>
using namespace std;vector<int> pos[26];
int main() {string s;cin >> s;int lgh = s.length();for(int i = 0; i < lgh; i++) {int index = s[i] - 'a';if(!pos[index].size()) pos[index].push_back(-1); pos[index].push_back(i);}for(int i = 0; i < 26; i++)if(pos[i].size()) pos[i].push_back(lgh);long long ans = 0;for(int i = 0; i < 26; i++)if(pos[i].size())for(int j = 1; j < pos[i].size() -1; j++) ans += (pos[i][j] - pos[i][j - 1] - 1) + (pos[i][j + 1] - pos[i][j] -1)+ 1ll * (pos[i][j] - pos[i][j - 1] - 1) * (pos[i][j + 1] - pos[i][j] - 1);ans += lgh; cout << ans << endl;return 0;
}
6.小数第N位
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#define ll long long
using namespace std;
int b;
long long qpow(ll base,ll num)
{long long ans=1,r=1;while(num){if(num&1){ans=base*ans%(b*1000);}num>>=1;base=base*base%(b*1000);}return ans;
}
int main()
{ll a,c;cin>>a>>b>>c;cout<<(a*qpow(10,c+2)%(b*1000)/b);return 0;
}
蓝桥杯最终冲刺(冲刺Day2)相关推荐
- 蓝桥杯31天冲刺之十一 [java]
文章目录 天干地支(模拟) 包子凑数(动态规划) 求值(暴力) 青蛙跳杯子(BFS) 天干地支(模拟) 题目链接:https://www.lanqiao.cn/problems/1029/learni ...
- 蓝桥杯31天冲刺之二十三 [java]
文章目录 打包 约数个数 寻找三位数 第二点五个不高兴的小明 打包 题目链接:http://lx.lanqiao.cn/problem.page?gpid=T2978 这个是一道二分的题目,题目需要求 ...
- 蓝桥杯31天冲刺打卡(Day11)
Hallo,大家好!不知不觉就过了11天了,让我们共同努力吧! 目录 A 天干地支 解析: 代码: B 包子凑数 解析: 代码: C 求值 解析: 代码: D 青蛙跳杯子 解析: 代码: A 天干地支 ...
- 【蓝桥杯31日冲刺】冲刺第11日(C++)
- 蓝桥杯31天冲刺之十 [java]
文章目录 扫地机器人 全球变暖 机器人行走 数的幂次 扫地机器人 题目链接:https://www.lanqiao.cn/problems/199/learning/ 这个感觉有点难,放弃了 全球变暖 ...
- 【蓝桥杯31日冲刺】冲刺第4日(C语言)
- 2022年(第13届蓝桥杯省赛)Python 14 天夺奖冲刺营
2022年(第13届蓝桥杯省赛)Python 14 天夺奖冲刺营 2022.03.25 攒了一周的视频直播没有看,更新完了直接看合集. 数据结构基础之链表篇 什么是链表 链表是线性表的链式存取的数据结 ...
- 蓝桥杯试题 基础练习 BASIC-11 十六进制转十进制 JAVA——冲刺蓝桥杯第六天
目录 前言 试题 基础练习 十六进制转十进制 要点 思路一:常规做法--进制转换 字符 循环 本题代码 思路二:简单做法,使用java自带的方法 本题代码 前言 进制转化包括这篇我写了三篇了,这篇没讲 ...
- 【蓝桥杯真题】16天冲刺 Python
距离比赛很快了,希望和我一起准备的PY党能更加熟练的掌握Python! 1.距离和(模拟赛填空题) 问题描述: 两个字母之间的距离定义为它们在字母表中位置的距离.例如 A和 C 的距离为 2,L 和 ...
最新文章
- element ui中dialog相关问题
- 企业打开Redis的正确方式,来自阿里云云数据库团队的解读
- 7 SD配置-企业结构-定义-定义信贷控制范围
- python画简便的图-python如何画出漂亮的地图?网友:教教我呗
- Apache Flink 误用之痛
- Linux-文件结构、快捷键、安装软件和常用命令(1)
- php爬虫入门之phpspider框架
- 2021年低压电工模拟考试题库及低压电工作业考试题库
- cc2530单片机的内核是什么_ZigBee技术开发:CC2530单片机原理及应用简介,目录书摘...
- cad卸载工具_CAD安装失败都是红?
- SparkLink星闪技术之SLB概述
- html向下的箭头符号怎么打,向下的箭头怎么打
- GAIN: Missing Data Imputation using Generative Adversarial Nets学习笔记
- 正交试验设计的基本步骤
- STVP编译时出现“Error creating process for executable cxstm8”
- arm linux fpu,多媒体处理,利用ARM NEON/FPU提升performance
- linux下退出mysql
- python论文排版格式_一张图总结科研必备的软件清单,妈妈再也不用担心我的工作了...
- (原)Opencv中直方图均衡和图像动态范围拉伸的代码
- 澎思科技茹敏:人脸识别的泛安防落地及多维数据实战应用|量子位沙龙回顾