- 博客(10)
- 收藏
- 关注
原创 c++快读函数
十分重要的快读。inline long long read(){ long long n=0; char c=getchar(); bool f=c==‘-‘; if(f) c=getchar(); for(c>=‘0’;c=getcher();) n+=c-‘0’; if(f) n=-n; return n;}
2021-09-12 19:23:02
395
1
原创 题解:洛谷 P1104 生日
题目传送门写这道题,可以使用结构体,排序用sort快速排序。注意要使用algorithm算法头键。源代码:#include <iostream>#include <algorithm>#include <cstring>using namespace std;struct st_ { int y,m,d; int i; char name[1000];};bool cmp(st_ a,st_ b){ if(a.y==b...
2021-08-20 11:17:36
282
1
原创 题解:洛谷 B2028 反向输出一个三位数
一道水题。题目传送门可以使用字符串,先输入,然后倒着一个一个输出。#include <iostream>using namespace std;int main(){ char a[3]; cin>>a; cout<<a[2]<<a[1]<<a[0]; return 0;}
2021-08-19 10:20:09
464
原创 题解:洛谷 P1036 [NOIP2002 普及组] 选数
一道十分标准的dfs。质数判断#include <iostream>#include <cstdio>using namespace std;int a[30],n,k,ans=0;bool isprime(const int n){ if(n==1) return 0; for(int A=2;A<n;A++){ if(n%A==0) return 0; } return 1;}void dfs(int A,int m,i
2021-08-18 09:44:06
277
原创 求质数的2种方法
求质数是非常重要的。先说一种最基本的求法。bool isprime(const int n){ if(n==1) return 0; for(int A=2;A<n;A++){ if(n%A==0) return 0; } return 1;}枚举,从2开始,到n-1,如果没有一个是n的因数,那就返回1,是质数;如果有,就返回0,不是。另一种质数筛。bool ssb[1001000];//素数表void ycl(){//预处理素数...
2021-08-18 09:43:15
347
原创 题解:洛谷 P4431 [COCI2017-2018#2] Košnja
一道非常简单的数学题。分析:转弯次数为 长宽中最小值*2-2ans[n]=(a>b?b*2-2:a*2-2);三目运算符不懂的可以看一下这篇文章。完整源代码:#include <iostream>using namespace std;int main(){ int a,b,n,c,ans[1000000]; cin>>n; c=n; while(n--){ cin>>a>>b; ans[n]=(a>
2021-08-17 11:56:19
170
原创 三目运算符用法
三目运算符其实就是if、else的简写。表达式1 ? 表达式2 : 表达式3 ;表达式1返回一个bool值,如果返回true,就做表达式2,如果返回false,就做表达式3.a>b?max=a:max=b;上面的例子
2021-08-17 11:53:43
2164
1
原创 题解:洛谷P1239 计数器
一开始看到这道题,我以为需要用到什么神奇的算法。后来我用最简单的方法,竟然AC了。题目传送门源代码:#include<iostream>using namespace std;int main(){ long long n,A,B; int ans[10]={0};//清零 cin>>n; for(A=1;A<=n;A++){//一个数一个数地统计 B=A; while(B!=0){ ans[B%10]++;//统计个位 B/
2021-08-16 14:44:12
393
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人