摘要: #include using namespace std; //用位存,比较的时候直接取反看是否相等,不要异或 //这是我的做法,超时了, //其实他用的是取反的技巧避免了第二重循环,那么就判断去饭后的结果在不在就可以了,用hash加速 // int n,m,a[50000],cache[50000];//cache 0 1 // int main(){ // cin>>n>>m; /... 阅读全文
posted @ 2020-06-06 21:52 西伯利亚挖土豆 阅读(116) 评论(0) 推荐(0)
摘要: #include #include #include #include #include #include #include #include using namespace std; //只作为一个参考 //约定表达式都是合法的,且在一行内输入,并没有空格 //约定运算符有 + - * /(整除) ( ) //约定操作数都是一位正整数,没有负号 //获得前后两个的优先级 /... 阅读全文
posted @ 2020-06-06 21:52 西伯利亚挖土豆 阅读(162) 评论(0) 推荐(0)
摘要: #include using namespace std; //假设无平行边和a-b b-a的回路,cost可以是负值 //利用bellmanford算法求最短路径,因为需要最小cost //这个算法支持中途调用,但是调用时必须是最小cost状态,因为dp const int maxn=1001; int G[maxn][maxn],pre[maxn],n,m,flow[maxn][maxn],... 阅读全文
posted @ 2020-06-06 21:51 西伯利亚挖土豆 阅读(155) 评论(0) 推荐(0)
摘要: #include using namespace std; //最小割就是把起点及其他分成一个城市,终点及其他分成一个城市,当两个城市之间的线路的流量都满载时,的分法。 //当最大流算法结束时,flag数组不是0的都是从s可达的,而且不可达的原因是没有残余了,所以就找到了最小割 const int maxn=1001; int G[maxn][maxn],pre[maxn],n,m,flow[... 阅读全文
posted @ 2020-06-06 21:50 西伯利亚挖土豆 阅读(475) 评论(0) 推荐(0)
摘要: #include <bits/stdc++.h> using namespace std; #define MAX 200 #define INF 0x7fffffff //下标从1开始 int graph[MAX + 1][MAX + 1], points[MAX + 1], m, n; //任意图,只要权值是正即可 //动态规划算法,取最小值时可以用堆(优先队列) //只能运算符重载 < 。。 阅读全文
posted @ 2020-06-06 21:49 西伯利亚挖土豆 阅读(134) 评论(0) 推荐(0)
摘要: #include <bits/stdc++.h> using namespace std; #define MAX 200 #define DIAN 100 #define INF 0x7fffffff int u[MAX+1],v[MAX+1],w[MAX+1],first[MAX+1],next[MAX+1],graph[DIAN+1][DIAN+1]; int numdian,numbian 阅读全文
posted @ 2020-06-06 21:49 西伯利亚挖土豆 阅读(138) 评论(0) 推荐(0)
摘要: #include <bits/stdc++.h> using namespace std; #define MAX 200 #define INF 0x7fffffff //无向图,规定两点间只有一条边 //下标从1开始 int graph[MAX+1][MAX+1],points[MAX+1],numbian,numdian,circle[MAX+1]; struct mydata { int 阅读全文
posted @ 2020-06-06 21:48 西伯利亚挖土豆 阅读(123) 评论(0) 推荐(0)
摘要: #include<bits/stdc++.h> using namespace std; int n,k,a[10000],s=0; priority_queue<int,vector<int>,greater<int> > pq; int main() { cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=k;i++) pq.p 阅读全文
posted @ 2020-06-06 21:47 西伯利亚挖土豆 阅读(202) 评论(0) 推荐(0)
摘要: #include<bits/stdc++.h> using namespace std; string a,b; int s=0; void chg(int i){ if(a[i]=='o') a[i]='*'; else if(a[i]=='*') a[i]='o'; } int main() { cin>>a>>b; for(int i=0;i<a.size();i++){ if(a[i]!= 阅读全文
posted @ 2020-06-06 21:47 西伯利亚挖土豆 阅读(159) 评论(0) 推荐(0)
摘要: #include <iostream> #include <cstring> #define INF 0x7fffffff using namespace std; //蓝桥杯 ADV-6 //算法书上有 int a[20],n,k,MAX=0,best[20],y[10001]; //n张邮票,k种 //如何求具体的邮资区间?方法是求出y【k】=m,代表达到k的邮资最少需要m张票。 //然后顺序 阅读全文
posted @ 2020-06-06 21:44 西伯利亚挖土豆 阅读(375) 评论(0) 推荐(0)
摘要: #include using namespace std; // ofstream __f("E:/123.txt"); // #define cout __f //括号判断准则 // 括号前边为 “ - ”,且括号中为 “ + ” 或 “ - ”,不能删除; // 括号前边为 “ / ”,不能删除; // 括号后为 “ * ”,且括号中为 “ + ” 或 “ - ”,不能删除; // 有以... 阅读全文
posted @ 2020-06-06 21:43 西伯利亚挖土豆 阅读(260) 评论(0) 推荐(0)
摘要: #include using namespace std; //用bfs以为找到一个解就是最优的,类似于走迷宫 //不需要清除hash,因为这就是在状态图上进行bfs,隐式图,没法vis数组 typedef pair pp; const int mod=1000003; int ans=0x3f3f3f3f,d[][2]={{1,0},{-1,0},{0,1},{0,-1}},n,nx,ny;/... 阅读全文
posted @ 2020-06-06 21:43 西伯利亚挖土豆 阅读(154) 评论(0) 推荐(0)
摘要: #include using namespace std; //快速求幂,就是二分法 long long mod=1000000007L; long long pow1(int x,int y){ //判断奇偶,偶数返回0奇数返回1 if(y==0) return 1; long long q=pow1(x,y/2);//注意只调用一遍,否则On if(y&1) ... 阅读全文
posted @ 2020-06-06 21:42 西伯利亚挖土豆 阅读(178) 评论(0) 推荐(1)
摘要: #include <iostream> #include <cstdio> using namespace std; int s=0; int f(int x){ int i=2,res=1;//因为x可能为1.。。。 while (x>1) { if(x%i==0){ //这里实际上是使劲除,除干净的方式,因为i没有++ x=x/i; res=i; s++; }else { i++; s=0; 阅读全文
posted @ 2020-06-06 21:39 西伯利亚挖土豆 阅读(491) 评论(0) 推荐(0)
摘要: #include <iostream> using namespace std; int a=100,b=20; int gcd(int a,int b){ return b==0?a:gcd(b,a%b); //注意最好先除再乘,否则可能溢出.因为a肯定可以被gcd整除 } int lcm(int a,int b){ return a/gcd(a,b)*b; } //gcd应用: //判断 (x 阅读全文
posted @ 2020-06-06 21:38 西伯利亚挖土豆 阅读(154) 评论(0) 推荐(0)
摘要: #include <iostream> #include <cstdio> using namespace std; long long x; //使用公式 int f1(){ int s=1; long long xx=x,i=2; int count1=0,flg=0; while (xx>1) { if(xx%i==0){ xx=xx/i; count1++; }else{ i++; if( 阅读全文
posted @ 2020-06-06 21:37 西伯利亚挖土豆 阅读(124) 评论(0) 推荐(0)
摘要: #include<bits/stdc++.h> using namespace std; typedef long long ll; //求小数点后第n位,很容易想到(a*10^(n+2)/b)%1000,即可得到数值,注意输出的时候左边补充0 //但是a*10^(n+2)太大了,long long 溢出了,利用公式x/d%m = (x%(d*m)/d)%m,直接获得等价类 //得到,((a*10 阅读全文
posted @ 2020-06-06 21:37 西伯利亚挖土豆 阅读(274) 评论(0) 推荐(0)
摘要: #include<bits/stdc++.h> using namespace std; //求逆元,方法是费马小定理,还有一种更快的线性算法 long long mod=1000000007L; int pow_mod(int x,int y,int c){ if(y==0) return 1; int q=pow_mod(x,y/2,c)%c; if(y&1) return (q*q*x)%c 阅读全文
posted @ 2020-06-06 21:35 西伯利亚挖土豆 阅读(337) 评论(0) 推荐(0)
摘要: #include<bits/stdc++.h> using namespace std; long long n; int main() { while(cin>>n){ //求素因子分解,加速原理,所有的数,如果有比sqrt(n)大的素因子,最多只有1种,1个 long long s=0,t=2,sq=(long long)sqrt(n); while(n>1){ while(n%t==0){ 阅读全文
posted @ 2020-06-06 21:34 西伯利亚挖土豆 阅读(169) 评论(0) 推荐(0)
摘要: #include <iostream> #include <cstdio> //阶乘的最后一个非0数 //即去掉因子5,2;计算乘积的个位 //乘积的个位=仅仅对每个数的个位进行乘积,每次都%10即可;连锁起来了 using namespace std; // int main(){ // int x,s=0,q=1; // cin>>x; // for(int i=2;i<=x;i++){ // 阅读全文
posted @ 2020-06-06 21:34 西伯利亚挖土豆 阅读(312) 评论(0) 推荐(0)