随笔分类 - 数学
摘要:三分法求下凸函数的最小值,可知,max(下凸函数,下凸函数)得到的函数认为下凸函数 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 using namespace std; 5 const int maxn=10000+10; 6 double a[maxn],b[maxn],c[maxn]; 7 int n; 8 double solve(double x) 9 {10 double maxv=a[0]*x*x+b[0]*x+c[0];11 for(int i=0;i<n;
阅读全文
摘要:置换的应用。若一个置换B中所有的元素个数为偶数的循环节和它元素相等的循环节的个数为偶数个,就存在置换A使得A^2=B 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int maxn=30; 6 char s[maxn]; 7 int vis[maxn],cou[maxn]; 8 int main() 9 {10 int n;11 scanf("%d",&n);12 while(n--)13
阅读全文
摘要:polya定理+欧拉函数优化,1641ms水过,具体参考的解题报告:http://www.cnblogs.com/staginner/archive/2012/03/08/2385052.html 1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 typedef long long LL; 5 int n,p; 6 int get_Eu(int x) 7 { 8 int i; 9 int ans=x;10 fo...
阅读全文
摘要:置换循环的应用。起初的状态为1,2,3......n,变换一次变为题目给出的序列,找出每个循环,可知每次变换每个字符的位置都是由本循环中的位置循环移动而来,通过模运算可得出每个字符在变换了多次之后,应该在的位置。 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int maxn=200+10; 6 char s[maxn],re[maxn]; 7 int num[maxn],vis[maxn],cir[maxn][max
阅读全文
摘要:polya定理的基础题目。置换群中有两种情况。#include <iostream>
#include <cstdio>
#define LL long long
using namespace std;
const int maxn=30;
LL pow[maxn];
int gcd(int a,int b)
{ return b==0?a:gcd(b,a%b);
}
int main()
{ pow[1]=3; int i; for(i=2;i<=24;i++) pow[i]=pow[i-1]*(LL)3; int n; while(scan...
阅读全文
摘要:约瑟夫问题,感谢这篇博客,让我想了两天之后,看了n篇解题报告都没想懂的情况下,彻底搞懂了这个问题blog.csdn.net/tsaid/article/details/7313382#include <iostream>
#include <cstdio>
using namespace std;
int f[15];
int solve(int n,int m)
{ int i,loc=0; for(i=1;i<=n;i++) { loc=(loc+m-1)%(2*n-i+1); if(loc<n) return 0; } ...
阅读全文
摘要:组合数学,对于长度为l的二进制数n,先求出长度小于l的满足意义的数,这里长度为l的数,都是指二进制以1开头的长度为为l的数,讨论以0开头的数在这种方法下没什么意义,因为每个数都可确定的知道其长度,并且是以1开头的,也就是说这样的分类可以包括所有的数并且没有重叠。然后再求长度为为l的小于n的满足要求的书。然后再检查n看他本身是否满足条件。这样就求出了1~n中满足条件的数的个数,还有c++提交除以2用位运算来实现,不然会wa#include <iostream>
#include <cstdio>
using namespace std;
int f[33][33],re[
阅读全文
摘要:递推,统计,数位DP水题,但这题在网上归为组合数学,不知道思路#include <iostream>
#include <cstdio>
#include <cstring>
#define LL long long
using namespace std;
LL f[11][30];
int main()
{ char s[11]; int i,j,k; for(i=0;i<26;i++) f[0][i]=1; for(i=1;i<10;i++) { for(j=0;j<(26-i);j++) { ...
阅读全文
摘要:这道题学会的就是从结果想问题,找到应该考虑的方向如果存在一直线l,使所有线段在l上的投影有交点,考虑只有一个交点这个极限,过此交点m做l的垂线,所有线段上的那个在l上的投影是m的点肯定过此垂线,所以存在直线l的必要条件就是至少存在一条直线交所有的线段,然后很显然至少存在一条直线交所有的线段是存在直线l的充分条件,所以原问题就转化为了是否有一条直线交所有的线段,而这一问题,可转换为是否存在过某两条线段的某两个不重合的端点的直线,交所有的线段。但太粗心了,这道题经该了4个小时,才把所有错误改完啦,ai~~~~~~~~~~~#include <iostream>
#include <
阅读全文
摘要:叉积+二分通过叉积来判断点在线段的某侧,找到在点右侧的最左边的边,即可判断点在第几个格子内,可以通过二分来优化查询速度#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int maxn=1000+10;
int n,m,x1,y1,x2,y2;
struct segment
{ int loc1,loc2;
};
segment s[maxn];
int c[maxn],res[maxn];
bool cmp(segment a,segm
阅读全文
摘要:数论 模#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
const int maxn=110;
char n[maxn],m[maxn];
int int_m;
int len1,len2;
int judge()
{ if(len1>len2) return 1; char tn[maxn],tm[maxn]; int i,j; for(i=len1-1,j=0;i>=0;i--,j++) tn[j]=n[i]; tn[j]='
阅读全文
摘要:大整数取模,脑袋怎么就不开窍呢//我太愚蠢啦
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
char s[200];
int main()
{ while(gets(s)) { if(strcmp(s,"0")==0) break; int i; int len=strlen(s); int ou=0; for(i=0;i<len;i++) { ou=((ou*10)%17+(s[i]-'0')%17)%17
阅读全文
摘要:素数唯一分解定理#include <iostream>
#include <math.h>
using namespace std;
long long f[15][110];
int t[110];
int main()
{ long long m,n; for(int i=1;i<=10;i++) { t[i]=0; for(int j=0;j<=i;j++) { for(int k=0;k<=i;k++) { long long x=(long long)(pow(2,double(j))*pow(5,double(k))); if(x<(
阅读全文
摘要:最最基础的dp,刚刚开始刷dp题,想了一到自认为很难理解的dp题(网上说是水题,但对于菜鸟我来说,貌似有点难度),想了一下午都没想清楚他的原理,先水这一道题,之后再仔细想想那道“水”题的原理#include <iostream>
using namespace std;
const int maxn=101;
int tri[maxn][maxn],f[maxn][maxn];
int n;
int main()
{ while(cin>>n) { int i,j; for(i=1;i<=n;i++) { for(j=1;j<=i;j++) cin>&
阅读全文
摘要:哎,折腾了一中午,终于ac拉。考察的是欧拉算法的扩展。我在此题中,思考的时间最长的部分就是通过扩展了欧拉算法得到了解后,如何得到最小的正整数解。对于这个小问题,我却百思不得其解。然后在网上找了解题报告后,才有了思路,就是先求出解系,然后通过这个解系的式子得到最小的整数解#include <iostream>
#include <cmath>
using namespace std;
void gcd(long long a,long long b,long long &gcdd,long long &w,long long &t)
{ if(b=
阅读全文
摘要:数论唯一分解定理的应用,要注意负数的情况,想明白这个过程用了两个小时,后来因为一个while写成了if有调试了俩小时,为什么还是这么菜数论唯一分解定理的应用,要注意负数的情况,想明白这个过程用了两个小时,后来因为一个while写成了if有调试了俩小时,为什么还是这么菜
#include <iostream>
#include <cmath>
using namespace std;
int gcd(int a,int b)
{ if(b==0) return a; else return gcd(b,a%b);
}
int main()
{ long long n; w
阅读全文
摘要:很基础的一道数学题,不过感觉跑的太慢啊,422ms#include <iostream>
#include <cmath>
using namespace std;
const int maxn=1000001;
int vis[maxn],p[maxn];
int t;
void prime()
{ t=0; int i,j; int n=(int)sqrt(maxn-1); for(i=2;i<=n;i++) { if(!vis[i]) { p[t++]=i; for(j=i*i;j<=maxn-1;j+=i) vis[j]=1; } }
}
i...
阅读全文

浙公网安备 33010602011771号