随笔分类 -  洛谷

摘要:位运算快速版: #include<iostream> using namespace std; long sum,upperlim=1; void test(long row,long ld,long rd) { if(row!=upperlim) { long pos=upperlim&~(row 阅读全文
posted @ 2020-03-30 16:06 BlueValentines 阅读(102) 评论(0) 推荐(0)
摘要:import java.util.Scanner; public class Main { public static final int[] prime = { 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 阅读全文
posted @ 2020-03-30 09:31 BlueValentines 阅读(105) 评论(0) 推荐(0)
摘要:import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int row,column,enter; while 阅读全文
posted @ 2020-03-27 17:20 BlueValentines 阅读(86) 评论(0) 推荐(0)
摘要:DFS 基本思路:搜索 标记 AC import java.util.Scanner;public class Main { static int[] a=new int[100]; static int[] b=new int[100]; static int[] c=new int[100]; 阅读全文
posted @ 2020-03-25 18:55 BlueValentines 阅读(451) 评论(0) 推荐(0)
摘要:题解: #include<iostream>using namespace std;int r=0;void swap(int &a,int &b){ int t=a; a=b; b=t; }void sort(int s[],int l,int r,int n[],int c[]){ int mi 阅读全文
posted @ 2020-02-18 10:18 BlueValentines 阅读(143) 评论(0) 推荐(0)
摘要:题解: 需要注意的是,快排完之后并不是按照编号从小到大的顺序输出 #include<iostream>using namespace std;int r=0;void swap(int &a,int &b){ int t=a; a=b; b=t; }void sort(int s[],int l,i 阅读全文
posted @ 2020-02-17 12:20 BlueValentines 阅读(111) 评论(0) 推荐(0)
摘要:题解: 需要注意的是,快排完之后并不是按照编号从小到大的顺序输出 #include<iostream>using namespace std;int r=0;void swap(int &a,int &b){ int t=a; a=b; b=t; }void sort(int s[],int l,i 阅读全文
posted @ 2020-02-17 11:24 BlueValentines 阅读(153) 评论(0) 推荐(0)
摘要:题解: 此题的关键不在排序,而在于大数字 我们可以用字符串进行存储,比较他们的长度,长度一样时比较他们的大小即可 #include<iostream>using namespace std; int main(){ int n; cin>>n; int ret=0,pre=0; string max 阅读全文
posted @ 2020-02-17 10:05 BlueValentines 阅读(156) 评论(0) 推荐(0)
摘要:题解: import java.util.HashSet;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); 阅读全文
posted @ 2020-02-14 21:43 BlueValentines 阅读(185) 评论(0) 推荐(0)
摘要:题解: #include<iostream>using namespace std;int ret=0,m_n;void p(int n,double k,int j){ if(k==1){ if(n>=j){ ret++; return; }else{ return; } } for(int i= 阅读全文
posted @ 2020-02-13 10:58 BlueValentines 阅读(151) 评论(0) 推荐(0)
摘要:埃氏筛法 埃氏筛法的基本思想 :从2开始,将每个质数的倍数都标记成合数,以达到筛选素数的目的。代码 : int visit[maxn]; void Prime(){ mem(visit,0); //初始化都是素数 visit[0] = visit[1] = 1; //0 和 1不是素数 for (i 阅读全文
posted @ 2020-02-13 10:12 BlueValentines 阅读(251) 评论(0) 推荐(0)
摘要:题解: 这其实是变相的斐波那契,观察下列等式: //k=2 : 1 2 3 5 8 13 21 34...... //k=3 : 1 2 4 7 13 24 44 81... //k=4 : 1 2 4 8 15 29 56 108... //k=5 : 1 2 4 8 16 31 61 120.. 阅读全文
posted @ 2020-02-11 10:59 BlueValentines 阅读(130) 评论(0) 推荐(0)
摘要:题解: #include<iostream>#include<cmath>using namespace std; int main(){ int m,n; cin>>m>>n; int a[n],b[m]; int ret=0; int c,c1=0; for(int i=0;i<n;i++){ 阅读全文
posted @ 2020-02-10 11:25 BlueValentines 阅读(148) 评论(0) 推荐(0)
摘要:题解: 从最后一个输入的数据开始排查,如果说你找到了这个点上面有地毯,那么就直接输出这个值,如果没找到就按照题干的意思输出-1。 #include<iostream>#include<cmath>using namespace std; int main(){ int n; cin>>n; int 阅读全文
posted @ 2020-02-09 11:53 BlueValentines 阅读(128) 评论(0) 推荐(0)
摘要:取余运算有一些好用的性质,包括: (A+B)modb=(Amodb+Bmodb)modb (A×B)modb=((Amodb)×(Bmodb))modb 算法: int mod3(int x,int n,int mod){ x=x%mod;///这里就是改进的那一步 int ans=1; for(i 阅读全文
posted @ 2020-02-08 11:44 BlueValentines 阅读(252) 评论(0) 推荐(0)
摘要:题解: 这道题用传统快排(如下所示)的结果就是最后三个点TLE: 如果永远取第一个元素作为枢轴的话,在数组已经有序的情况下每次划分都将得到最坏的结果,时间复杂度退化为O(n^2)。因为其中一个子序列每次都只比原序列少一个元素,该侧的递归深度将达到最大。 #include<iostream>using 阅读全文
posted @ 2020-02-07 12:06 BlueValentines 阅读(158) 评论(0) 推荐(0)
摘要:题解: 这道题告诉我们:有些题不必死算,可以找规律 #include<stdio.h> int main(){ int n,i;//i为第几组数字,n为总序数 scanf("%d",&n); for(i=1;i<n;i++){ n-=i; if(n<=0){ n+=i; break; } }//n为 阅读全文
posted @ 2020-02-06 10:35 BlueValentines 阅读(129) 评论(0) 推荐(0)
摘要:题解: 原先我想的还是一个一个地输出,但看了一些大佬的写法,发现其实此题很简单 简单的题解: 输入int的时候它不会自动舍去前面的0吗 负的乘以整的不还是负的吗 #include <iostream>using namespace std;int n,k;int main(){ cin >> n; 阅读全文
posted @ 2020-02-04 11:18 BlueValentines 阅读(109) 评论(0) 推荐(0)
摘要:题解: 在测试数据里有一个是临界值问题,探测范围是闭区间 #include<stdio.h>int main(){ double s,x; //注意:此题所有的变量都是浮点数,说的是实数,不是整数 scanf("%lf %lf",&s,&x); double a=s-x,b=s+x; double 阅读全文
posted @ 2020-02-03 15:51 BlueValentines 阅读(132) 评论(0) 推荐(0)
摘要:题解: #include<stdio.h>int main(){ int A,B,C; scanf("%d %d %d",&A,&B,&C); int a,c,b,d,e,f,z,x,y; int i,j,k; int ret=0; for(i=123;i<345;i++){ //如果进行3次循环的 阅读全文
posted @ 2020-02-02 12:00 BlueValentines 阅读(127) 评论(0) 推荐(0)