拖拖拖了好久的校赛补题nefu1259&nefu1260&nefu1261&nefu1262&nefu1263&nefu1264
来源:互联网 发布:android 取消网络请求 编辑:程序博客网 时间:2024/06/14 21:56
NEFU1259
题目:
还记得矩阵快速幂吗?给出如下递推方程:f(n)=f(n-1)+2^(n-1) 其中 f(1)=1,求 f(n)
快速幂模板题(一开始居然想用递归真是脑子烧坏了)
using namespace std;typedef long long ll;const int mod=1e9+7;ll quickmod(ll m,ll n){ ll ans=1; while(n) { if(n&1) ans=ans*m%mod; m=m*m%mod; n>>=1; } return ans%mod;}int main(){ ll t,n; while(cin>>t) { while(t--) { cin>>n; cout<<(quickmod(2,n)-1)%mod<<endl; } } return 0;}
NEFU1260
题目
给定f(n)=n^a+n^(a+1)+...+n^(b-1)+n^b求f(n)%MOD需要用到快速乘法(模比较大)和注意特判n
#include <iostream>using namespace std;typedef long long ll;const ll mod=10000000033;ll cf(ll b,ll m){ ll ans=0; while(m) { if(m&1) ans=(ans+b)%mod; b=(b+b)%mod; m/=2; } return ans;}ll quickmod(ll m,ll n){ ll ans=1; while(n) { if(n&1) ans=cf(ans,m)%mod; n/=2; m=cf(m,m)%mod; } return ans%mod;}int main(){ ll t,a,b,n; cin>>t; while(t--) { cin>>a>>b>>n; ll ans=0; if(a>b) swap(a,b); if(n==1) ans=b-a+1; else if(n==0) ans=0; else ans=cf((quickmod(n,b+1)-quickmod(n,a)+mod)%mod,quickmod(n-1,mod-2))%mod; // cout<<quickmod(n,b+1)-quickmod(n,a)+mod<<endl; // cout<<quickmod(n,b+1)<<" "<<quickmod(n,a)<<endl; // cout<<quickmod(n-1,mod-2)<<endl; cout<<ans%mod<<endl; } return 0;}NEFU1261
题目
给定空间4个点的坐标(x,y,z),求这四个点围成的图形的体积,结果保留两位小数
公式题,发现了体积的海伦公式但是没过,用的别的公式(求大佬看看类海伦公式咋错了)
//类海伦公式#include <iostream>#include <math.h>#include <stdio.h>using namespace std;typedef struct node{ double x,y,z;}ss;double dis(node a,node b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));}int main(){ int t;cin>>t; while(t--) { ss tt[5]; cin>>tt[0].x>>tt[0].y>>tt[0].z; cin>>tt[1].x>>tt[1].y>>tt[1].z; cin>>tt[2].x>>tt[2].y>>tt[2].z; cin>>tt[3].x>>tt[3].y>>tt[3].z; double a,b,c,j,k,l; c=dis(tt[0],tt[1]); a=dis(tt[0],tt[2]); b=dis(tt[0],tt[3]); j=dis(tt[1],tt[3]); k=dis(tt[1],tt[2]); l=dis(tt[2],tt[3]); double f,g,t; f=acos((a*a+c*c-k*k)/(2*a*c)); g=acos((b*b+c*c-j*j)/(2*b*c)); t=acos((b*b+a*a-l*l)/(2*b*a)); // cout<<f<<g<<t<<endl; double p=(f+g+t)/2; double s=sqrt(fabs(sin(p)*sin(p-f)*sin(p-g)*sin(p-t))); double v=a*b*c*s*1/3; printf("%.2lf\n",v); } return 0;}
//AC代码#include <iostream>#include <math.h>#include <stdio.h>using namespace std;typedef struct node{ double x,y,z;}ss;double dis(node a,node b){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z);}int main(){ int t;cin>>t; while(t--) { ss tt[5]; cin>>tt[0].x>>tt[0].y>>tt[0].z; cin>>tt[1].x>>tt[1].y>>tt[1].z; cin>>tt[2].x>>tt[2].y>>tt[2].z; cin>>tt[3].x>>tt[3].y>>tt[3].z; double a,b,c,d,e,f; a=dis(tt[0],tt[1]); b=dis(tt[0],tt[2]); c=dis(tt[0],tt[3]); e=dis(tt[1],tt[3]); f=dis(tt[1],tt[2]); d=dis(tt[2],tt[3]); /*double f,g,t; f=acos((a*a+c*c-k*k)/(2*a*c)); g=acos((b*b+c*c-j*j)/(2*b*c)); t=acos((b*b+a*a-l*l)/(2*b*a)); // cout<<f<<g<<t<<endl; double p=(f+g+t)/2; double s=sqrt(fabs(sin(p)*sin(p-f)*sin(p-g)*sin(p-t))); double v=a*b*c*s*1/3;*/ double v=sqrt(a*d*(b+c+e+f-a-d)+b*e*(a+c+d+f-b-e)+c*f*(a+b+d+e-c-f)-a*b*f-b*c*d-c*a*e-d*e*f)/12; printf("%.2lf\n",v); } return 0;}
NEFU1262
题目
求一个数的因子和模板题(but最后x>1出了问题)
#include <iostream>#include <string.h>using namespace std;typedef long long ll;int prime[1000005];int vis[1000005],cnt;void init(){ cnt=0; memset(vis,0,sizeof(vis)); for(int i=2; i<50005; i++) { if(!vis[i]) { prime[cnt++]=i; for(int j=i+i; j<50005; j+=i) vis[j]=1; } }}ll cf(ll b,ll m, ll tt){ ll ans=0; while(m) { if(m&1) ans=(ans+b)%tt; m>>=1; b=(b+b)%tt; } return ans;}ll quick(ll m,ll n){ ll ans=1; while(n) { if(n&1) ans=ans*m; m=m*m; n>>=1; } return ans;}int main(){ ll t,a; init(); while(cin>>t) { while(t--) { cin>>a; ll ans=1; ll x=a; for(int i=0; i<cnt; i++) { if(a%prime[i]==0) { ll tmp=0; while(x%prime[i]==0) { tmp++; x/=prime[i]; } ans*=(quick(prime[i],tmp+1)-1)/(prime[i]-1); } } if(x>1) { ans=ans+ans*x; } cout<<ans<<endl; } } return 0;}NEFU1263
题目
BD有最近在玩一个游戏,当然玩游戏肯定需要很多游戏币,某公司最新推出了一款新型的游戏币,这款新型游戏币有 n 种币值,其中币值为v_i的有 w_i 个,现在BD手里只有一个 x 元的游戏币,为了方便,她想换成零钱,问有多少种方案?母函数模板题
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;#define MAX 100int v[55],n2[55],n1[55];int main(){ int t; cin>>t; while(t--) { int n,P; cin>>n; for(int i=0; i<n; i++) { cin>>v[i]>>n2[i]; n1[i]=0; } cin>>P; int a[MAX],b[MAX]; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); a[0]=1; for (int i=0; i<n; i++) { memset(b,0,sizeof(b)); for (int j=n1[i]; j<=n2[i]&&j*v[i]<=P; j++) for (int k=0; k+j*v[i]<=P; k++) b[k+j*v[i]]+=a[k]; memcpy(a,b,sizeof(b)); } int ans=0; cout<<a[P]<<endl; } return 0;}
NEFU1264
题目
平面上有n个点,每个点有各自的速度向量,现在给出0时刻,在同一时刻,平面点的最远距离叫做special dis他们每个点的位置和每个点的速度向量,现在求在哪个时刻的时候,他们的special dis 最小,并输出这个距离。求最大的最小用三分。。暴力TLE
//TLE#include <iostream>#include <math.h>#include <stdio.h>using namespace std; int t,n;typedef struct node{ double x,y,vx,vy;}tt;tt s[10005];double dis(node a,node b,double t){ double x1=a.x+t*a.vx; double y1=a.y+t*a.vy; double x2=b.x+t*b.vx; double y2=b.y+t*b.vy; double xx=x1-x2; double yy=y1-y2; double dis=pow(pow(xx,2)+pow(yy,2),0.5); return dis;}double calc(double t){ double maxn=0.0; for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) { double disn=dis(s[i],s[j],t); maxn=max(maxn,disn); } return maxn;}void solve(){ double L=0.0,R=200000,M; double RM=0,LM; while(R-L>0.01) { M = (L + R) / 2; LM = (M + L) / 2; RM=LM+0.001; if (calc(LM) < calc(RM)) R = LM; else L = LM; } printf("%.2lf %.2lf\n",LM,calc(LM)); // cout<<LM<<" "<<calc(LM)<<endl; // return L;}int main(){ cin>>t; while(t--) { cin>>n; for(int i=0;i<n;i++) scanf("%lf%lf%lf%lf",&s[i].x,&s[i].y,&s[i].vx,&s[i].vy); solve(); } return 0;}
旋转卡壳+凸包
#include <iostream>#include <math.h>#include <stdio.h>#include <algorithm>using namespace std;int ts,n;typedef struct node{ double x,y,vx,vy;} tt;tt s[10005],zz[10005];int top;int ss[10005];double cross(node a,node b,node c)//叉积{ return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);}double dis(node a,node b)//距离{ return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}bool cmp(node a,node b){ double ans = cross(s[0],a,b); if( ans > 0 || (ans == 0 && dis(s[0],a) > dis(s[0],b) )) return true; return false;}void graham(double t)//凸包模板。。{ for(int i=0; i<n; i++) { s[i].x=(zz[i].x+zz[i].vx*t); s[i].y=(zz[i].y+zz[i].vy*t); } int u=0; for(int i = 1; i != n; i ++) //寻找基点 { if(s[u].y > s[i].y || (s[u].y == s[i].y && s[u].x >s[i].x)) u = i; } if(u) { swap(s[u].y,s[0].y); swap(s[u].x,s[0].x); } sort(s + 1,s + n,cmp); ss[0] = 0; ss[1] = 1; top = 1; for(int i = 2; i != n ; i ++) { while(top && cross(s[ss[top - 1]],s[ss[top]],s[i] ) < 0) top--; ss[++top] = i; } top ++;}double RC(double t)//旋转卡壳{ graham(t); int q,p1,pp,qq,rr,r; double ans = 0; q = 1; ans = dis(s[ss[0]],s[ss[1]]); for(int i = 0; i != top ; i ++) { while(fabs(cross(s[ss[(i+1)%top]],s[ss[i%top]],s[ss[(q+1)%top]])) > fabs(cross(s[ss[(i+1)%top]],s[ss[i%top]],s[ss[q%top]]))) q = (q + 1)%top; ans = max(ans, max(dis(s[ss[(i+1)%top]],s[ss[q]]),dis(s[ss[i%top]],s[ss[q]]))); } return ans;}void solve(){ double L=0.0,R=200000,M; double RM=0,LM; /* while(R-L>1e-6) { M = (L + R) / 2; LM = (M + L) / 2; RM=LM+0.0001; if (RC(LM) < RC(RM)) R = LM; else L = LM; } }*/ while(R-L>1e-6) { M=(L+R)/2; RM=(M+R)/2; if (RC(M) <= RC(RM)) R = RM; else L=M; } printf("%.2lf %.2lf\n",L,RC(L)); // cout<<LM<<" "<<calc(LM)<<endl; // return L;}int main(){ cin>>ts; while(ts--) { cin>>n; for(int i=0; i<n; i++) scanf("%lf%lf%lf%lf",&zz[i].x,&zz[i].y,&zz[i].vx,&zz[i].vy); solve(); } return 0;}
阅读全文
0 0
- 拖拖拖了好久的校赛补题nefu1259&nefu1260&nefu1261&nefu1262&nefu1263&nefu1264
- 传了好久的照片
- 纠结了好久的递归
- CSDN的帐号注册的好久好久了
- 数据结构 【joseph环】 写了好久好久的~
- 心爱的eclipse好久没用了
- 今天发了好久的呆!
- 好久没用 CSDN 的 Blog 了
- 好久没听beyond的歌了
- 好久没有更新我的Blog了
- 好久没照顾自己的博客了
- 好久没看到UML的论战了
- 折腾了好久的Linux设备驱动
- 好久没有学生的感觉了
- 琢磨了好久的ruby email
- 亲爱的博客,好久没来了
- 好久没有呼吸道清晨的微风了
- 真正的opencv配置,搞了好久。
- 【提高组NOIP2008】传纸条
- git笔记(相见恨晚的技术)
- 【EasyUI】EasyUI主页面布局:左侧菜单tree、tabs选项卡、tabs右键菜单
- Base封装
- 实现数据驱动型企业,只需五步!
- 拖拖拖了好久的校赛补题nefu1259&nefu1260&nefu1261&nefu1262&nefu1263&nefu1264
- 大数据揭秘:低学历成功逆袭概率多少?
- php 导出excel打不开
- iOS实现app之间的内容分享总结
- Java虚拟机类加载过程
- HTML+JS 写一个 个人博客(初学版)
- 嵌入式环境搭配和开发基本名词解析
- 系统开发模型
- 路由器FTP服务的配置