随笔分类 -  数学

摘要:前三题特水~~~~第四题,迪杰斯特拉算法。只需在裸的算法改点东西就行#include#include#include#include#define maxn 100005#define inf 1t.d; }};struct Di{ int n,m,ans; vectored; ... 阅读全文
posted @ 2014-07-21 15:19 Yours1103 阅读(150) 评论(0) 推荐(0)
摘要:题意一直没看懂~~~~不过看懂了之后还是感觉挺好的#include#include#include#define maxn 32using namespace std;int n;double p[maxn],t;void pre(){ p[0]=1; for(int i=1;i=0;i... 阅读全文
posted @ 2014-07-19 15:06 Yours1103 阅读(101) 评论(0) 推荐(0)
摘要:直接枚举计算就行;#include#include#include#define maxn 22using namespace std;double ans[maxn],p[maxn];bool vis[maxn];int n,r;void dfs(int cur,int cot){ if(c... 阅读全文
posted @ 2014-07-18 17:19 Yours1103 阅读(194) 评论(0) 推荐(0)
摘要:扩展欧几里得#include#include#include#include#define maxn 3000009#define ll long longusing namespace std;void gcd(ll a,ll b,ll& d,ll& x,ll &y){ if(!b){d=a... 阅读全文
posted @ 2014-07-17 11:27 Yours1103 阅读(247) 评论(0) 推荐(0)
摘要:#include#includeusing namespace std;int k,n;void dfs(int a,int b,int c,int d){ if(kn)return ; dfs(a,b,x,y); --k; if(k==0){printf("%d/%d\n",x,y);k--;return;} dfs(x,y,c,d);}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d",&n); scanf("%d",&k 阅读全文
posted @ 2014-03-24 17:34 Yours1103 阅读(113) 评论(0) 推荐(0)
摘要:两种构造的方式都是正确的;1.#include#include#include#define maxn 60#define ll long longusing namespace std;int x;ll M,n;struct matrix{ int len_x; int len_y; ll data[maxn][maxn]; void ini() { len_x=0; len_y=0; memset(data,0,sizeof data); }};matrix mat_big;ll f[maxn][maxn];ma... 阅读全文
posted @ 2014-03-10 22:58 Yours1103 阅读(252) 评论(0) 推荐(0)
摘要:在第8组数据上WA了一天,后来才发现问题;#include#include#include#include#define maxn 200009#define inf 1e15using namespace std;int n,k,q;struct node{ int score; int pain; bool operatorb.score;}bool vis[maxn];int s[maxn];long long check(int p){ long long ans=0; int cnt_1=0; for(int i=1;i=p-1)cnt_1++; ... 阅读全文
posted @ 2014-03-01 16:14 Yours1103 阅读(233) 评论(0) 推荐(0)
摘要:把前n个碟子从第一个塔移动到第三个塔有两种方法:1.把前n-1个移动到第二个塔,把第n个移动到第三个塔,然后把前n-1个从第二个移动到第三个;2.把前n-1个移动到第三个塔,把第n个移动到第二个塔,然后把前n-1个继续移动到第一个的塔,把第N个移动到第三个塔,最后把前n个移动到第三个塔就行了;状态转移方程:a=dp[i][3-i-j][k-1]+matrix[i][j]+dp[3-i-j][j][k-1];b=dp[i][j][k-1]+matrix[i][3-i-j]+dp[j][i][k-1]+matrix[3-i-j][j]+dp[i][j][k-1];dp[i][j][k]=min(a 阅读全文
posted @ 2014-02-21 13:43 Yours1103 阅读(273) 评论(0) 推荐(0)
摘要:我的方式是用暴力的方法找到每一行每一列的边界点;但是有大神直接用一个公式解决了:floor(n*sqrt(2))*4;想了很久还是不理解,求各路大神指点!#include#include#includeusing namespace std;int main(){ long long n; cin>>n; if(n==0){cout1) ans+=pre-cur-1; pre=cur; } ans--; cout<<ans*4;}View Code 阅读全文
posted @ 2014-02-19 23:23 Yours1103 阅读(243) 评论(0) 推荐(0)
摘要:详解见:http://blog.csdn.net/tri_integral/article/details/18666797#include#include#define maxn 105#includeusing namespace std;int s[maxn];int main(){ int n; int tmp; while(scanf("%d",&n)!=EOF) { memset(s,0,sizeof s); s[50]=n; bool flag; while(1) { ... 阅读全文
posted @ 2014-02-19 12:42 Yours1103 阅读(206) 评论(0) 推荐(0)
摘要:很直观的一个gauss题;用的是以前用过的一个模板;#include#include#include#include#define maxn 12#define eps 0.00001using namespace std;double matrix[15][15];double ans[15];void exchange_col(int p1,int p2,int n){ double t; int i; for(int i=0; ifabs(matrix[p][i])) p=j; if(p!=i) exch... 阅读全文
posted @ 2013-12-04 21:27 Yours1103 阅读(223) 评论(0) 推荐(0)
摘要:n个人,m种信仰;问你相邻的人信仰不同的情况有多少种?首先第一个人有m种选择,第二个人有m-1种选择,后面所有的人都只有m-1种选择;所以结果就是m^n-m*(m-1)^(n-1)#include#include#include#define ll long long#define mod 100003using namespace std;ll pow_mod(ll n,ll p){ ll ans=1; while(p) { if(p&1) ans=ans*n%mod; n=n*n%mod; p>>=1; } retur... 阅读全文
posted @ 2013-12-02 20:14 Yours1103 阅读(157) 评论(0) 推荐(0)
摘要:思路:二分答案,然后模拟消灭石头的过程;如果单纯的暴力模拟的话,肯定会T的;所以要用到一定的技巧来维护;在网上看到大神们用O(n)的复杂度来优化,真心orz;原理是这样的:用一个变量sum_2存前面所有的对当前石头造成影响的冲击波的损失的能量和;所以对于当前的石头所需要的新的冲击波的数量为:(当前石头的能量值-前面有影响的冲击波数*能量x+sum_2)/能量x+1;然后就是维护sum_2了!维护sum_2要利用这个公式:(x+1)^2=x^2+2*x+1; 1 #include 2 #define maxn 50005 3 #define ll long long 4 using namesp 阅读全文
posted @ 2013-11-08 19:55 Yours1103 阅读(423) 评论(0) 推荐(0)
摘要:对x的坐标三分; 1 #include 2 #include 3 #define maxn 10009 4 using namespace std; 5 double a[maxn],b[maxn],c[maxn]; 6 int n; 7 double f(double x) 8 { 9 double ans=-999999999.0,t;10 for(int i=0;i<n;i++)11 {12 t=a[i]*x*x+b[i]*x+c[i];13 ans=max(ans,t);14 }15 return ans;16 }... 阅读全文
posted @ 2013-11-06 21:06 Yours1103 阅读(149) 评论(0) 推荐(0)
摘要:组合游戏题;组合游戏的规则:1.必败态的所有后继都是必胜态;2.必胜态最少有一个必败的后继;这里的必胜态是f[1][0][0][0];其中f[a][b][c][d]表示有a个1,b个2,c个3,d个4是不是一个必胜态;可以认为大于3的奇数等同于3,大于4的偶数等同于4.然后递归求解; 1 #include 2 using namespace std; 3 4 bool vis[51][51][51][51]; 5 bool f[51][51][51][51]; 6 int F(int a,int b,int c,int d) 7 { 8 if (!vis[a][b][c][d]) ... 阅读全文
posted @ 2013-11-04 21:08 Yours1103 阅读(191) 评论(0) 推荐(0)
摘要:对于组合游戏的题;首先把问题建模成NIM等经典的组合游戏模型;然后打表找出,或者推出SG函数值;最后再利用SG定理判断是否必胜必败状态; 1 #include 2 #define ll long long 3 using namespace std; 4 5 ll sg(ll x) 6 { 7 return x%2==0 ? x/2 : sg(x/2); 8 } 9 10 int main()11 {12 int t;13 scanf("%d",&t);14 while(t--)15 {16 int n;17 ll a,... 阅读全文
posted @ 2013-11-01 23:17 Yours1103 阅读(239) 评论(0) 推荐(0)
摘要:逆序对数的应用;逆序对数的写法有,二分,树状数组,分治;学习一下;树状数组版:代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn=100010; 6 int a[maxn],b[maxn],c[maxn]; 7 int n; 8 struct point 9 {10 int num,index;11 bool operator0)35 {36 ans+=c[x];37 x-=lowbit(x);38 }39 return an... 阅读全文
posted @ 2013-10-26 20:58 Yours1103 阅读(366) 评论(0) 推荐(0)
摘要:这个题的方法很巧妙,首先将整个圆分成(m+n)份,这样移动后的点都是在整数值上;所以只要计算在这样的分法下原来的坐标就行了;代码: 1 #include 2 #include 3 using namespace std; 4 5 int main() 6 { 7 int m,n; 8 { 9 while(scanf("%d%d",&n,&m)!=EOF)10 {11 double ans=0;12 for(int i=1;i<n;i++)13 {14 ... 阅读全文
posted @ 2013-10-25 22:49 Yours1103 阅读(166) 评论(0) 推荐(0)
摘要:这个题目的证明挺美的;把分金币问题变成了一个数轴上点的距离问题;代码: 1 #include 2 #include 3 #define ll long long 4 #define maxn 1000009 5 using namespace std; 6 7 ll a[maxn],b[maxn],sum,m; 8 9 int main()10 {11 int n;12 while(scanf("%d",&n)!=EOF)13 {14 sum=0;15 for(int i=0;i<n;i++){scanf("%lld",&a[i]) 阅读全文
posted @ 2013-10-25 13:12 Yours1103 阅读(173) 评论(0) 推荐(0)
摘要:数值计算:这种积分的计算方法很好,学习一下!代码: 1 #include 2 #include 3 using namespace std; 4 const double eps = 10e-5; 5 6 double func(double a, double b, double x) 7 { 8 double r = a * exp(- x*x) + b * sqrt(x); 9 return r*r;10 }11 12 double integrate(double a, double b, double h)13 {14 unsigned long ste... 阅读全文
posted @ 2013-10-20 16:56 Yours1103 阅读(210) 评论(0) 推荐(0)