2019西北工业大学程序设计创新实践基地春季选拔赛(重现赛)补题笔记
2019-04-07 09:23
183 查看
#include <iostream> #include <cmath> #include <cstdio> #include <algorithm> using namespace std; double dis(double x1,double y1,double x2,double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } int main() { int ix0,iy0,ir,ix1,iy1,iy2; cin >> ix0 >> iy0 >> ir >>ix1 >> iy1 >> iy2; double x0 = (double)ix0,y0 = (double)iy0,r = (double)ir,x1 = (double)ix1,y1 = (double)iy1 ,y2 = (double)iy2; //printf("%lf %lf %lf %lf\n",y1,y2,x1,x0); double k = (y1-y2)/x1; double a=(1+k*k),b=(2*(y2-y0)*k-2*x0),c=x0*x0+(y2-y0)*(y2-y0)-r*r; double dlta = b*b - 4*a*c; double sx1 = (-b+sqrt(dlta))/(2*a),sx2 = (-b-sqrt(dlta))/(2*a); double sy1 = k*sx1 + y2 ,sy2 = k*sx2 + y2; //printf("%lf %lf %lf %lf\n",k,sy1,sx2,sy2); cout << (long long)(dis(sx1,sy1,x1,y1)*dis(sx2,sy2,x1,y1)+0.5) << endl; return 0; }
#include <iostream> #include <cmath> using namespace std; int main() { int n; cin >> n; int t = log(n)/log(2); if(n==(1<<t))cout << t << endl; else cout << t+1 << endl; return 0; }
#include <iostream> #include <algorithm> using namespace std; typedef long long ll; const ll mod = 1e9+7; ll exgcd(ll a,ll b,ll& x,ll& y){ if(a%b==0){ x=0,y=1; return b; } ll r,tx,ty; r=exgcd(b,a%b,tx,ty); x=ty; y=tx-a/b*ty; return 0; } ll comp(ll a,ll b,ll m){ if(a<b) return 0; if(a==b) return 1; if(b>a-b) b=a-b; ll ans=1,ca=1,cb=1; for(int i=0;i<b;i++){ ca=ca*(a-i)%m; cb=cb*(b-i)%m; } ll x,y; exgcd(cb,m,x,y); x=(x%mod+mod)%m; ans=ca*x%m; return ans; } ll lucas(ll a,ll b,ll m){ ll ans=1; while(a&&b){ ans=(ans*comp(a%m,b%m,m))%m; a/=m; b/=m; } return ans; } int main() { ll m,n; cin >> m >> n ; cout << lucas(n-1,m-1,mod) << ' ' << lucas(m+n-1,m-1,mod) << endl; return 0; }
#include <iostream> #include <algorithm> #include <cstdio> using namespace std; const int N = 1e5+10; int a ={0}; int main() { int n,q; scanf("%d%d",&n,&q); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); a[i]+=a[i-1]; } while(q--) { int x,l,r; scanf("%d%d%d",&x,&l,&r); double ans = a[r]-a[l-1]; double p = (r-l+1)/(double)n; printf("%.6lf\n",ans/(r-l+1)*(1-p)+(ans+x)/(r-l+1)*(p)); } return 0; }
G Chino with Train to the Rabbit Town
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> using namespace std; const int N =5e5+10; int w ,dp ={0},pre ; int main() { int n,k,mx=0; scanf("%d%d",&n,&k); memset(pre,-1,sizeof(pre)); dp[0]=w[0]=pre[0]=0; for(int i=1;i<=n;i++) { scanf("%d",&w[i]); w[i]^=w[i-1]; dp[i]=dp[i-1]; if(pre[w[i]^k]!=-1) dp[i]=max(dp[i],dp[pre[w[i]^k]]+1); mx=max(mx,dp[i]); pre[w[i]]=i; } printf("%d\n",mx); return 0; }
#include <iostream> #include <algorithm> #include <queue> #include <cstdio> #include <cstring> using namespace std; typedef pair<int,int> PII; const int N =2e3+10; struct s { int x,y,step,turns,d; s(int _x,int _y,int _s,int _t,int _d):x(_x),y(_y),step(_s),turns(_t),d(_d){} bool operator < (const s &a) const { if(a.turns!=turns)return a.turns < turns; else return a.step < step; } }; char mp ; int ans=0,vis ; pair<int,int>dir[4]={{1,0},{-1,0},{0,1},{0,-1}}; priority_queue <s> q; PII S,E; int n,m; int bfs() { int flag=1; while(!q.empty())q.pop(); q.push(s(S.first,S.second,0,0,0)); vis[S.first][S.second]=1; while(!q.empty()) { s z = q.top(); q.pop(); //cout << z.x << " " << z.y << " " << z.d << endl; if(z.x==E.first&&z.y==E.second) { printf("%d\n",z.turns); flag=0; return 0; } for(int i=0;i<4;i++) { int x1=z.x+dir[i].first,y1 = z.y+dir[i].second; if(x1>=0&&x1<n&&y1>=0&&y1<m&&(!vis[x1][y1])&&mp[x1][y1]!='*') { vis[z.x][z.y]=1; if(z.d==0) { if(i<2)q.push(s(x1,y1,z.step+1,z.turns,1)); else q.push(s(x1,y1,z.step+1,z.turns,2)); } else if(i<2) { if(z.d==1)q.push(s(x1,y1,z.step+1,z.turns,1)); else q.push(s(x1,y1,z.step+1,z.turns+1,1)); } else { if(z.d==1)q.push(s(x1,y1,z.step+1,z.turns+1,2)); else q.push(s(x1,y1,z.step+1,z.turns,2)); } } } } if(flag)printf("troil\n"); return 0; } int main() { memset(vis,0,sizeof(vis)); scanf("%d%d",&n,&m); getchar(); for(int i=0;i<n;i++) for(int j=0;j<=m;j++) { mp[i][j]=getchar(); if(mp[i][j]=='S')S = {i,j}; if(mp[i][j]=='T')E = {i,j}; } //printf("%d %d %d %d \n",S.first,S.second,E.first,E.second); bfs(); return 0; }
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> using namespace std; int n; struct ios { inline char read(){ static const int IN_LEN=1<<18|1; static char buf[IN_LEN],*s,*t; return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++; } template <typename _Tp> inline ios & operator >> (_Tp&x){ static char c11,boo; for(c11=read(),boo=0;!isdigit(c11);c11=read()){ if(c11==-1)return *this; boo|=c11=='-'; } for(x=0;isdigit(c11);c11=read())x=x*10+(c11^'0'); boo&&(x=-x); return *this; } } io; const int N=20; int w ,dp [1<<N]; int slove() { for(int i=0;i<n;i++)dp[i][1<<i]=w[i][i]; for(int i=1;i<(1<<n);++i) for(int j=0;j<n;++j) for(int k=0;k<n;++k) { if(((i&(1<<j))==0)&&(i&(1<<k))) { dp[j][i|(1<<j)]=max(dp[j][i|(1<<j)],dp[k][i]+w[j][k]); } } int mx=0; for(int i=0;i<n;i++)mx = max(dp[i][(1<<n)-1],mx); return mx; } int main() { scanf("%d",&n); for(int i=0;i<n;i++) for(int j=0;j<n;j++) io >> w[i][j]; printf("%d",slove()); return 0; }
相关文章推荐
- 2019西北工业大学程序设计创新实践基地春季选拔赛题解
- 2019知到app答案-创新工程实践 章节测试完整智慧树答案
- Unix/Linux编程实践教程 笔记8 进程和程序:编写命令解释器sh
- 黑马程序员——Objective-C程序设计(第4版)学习笔记之14-Foundation框架简介——黑马 IOS 技术博客
- C++程序设计实践学材系列(15)——1.3.1 帮电气工程师计算电阻值
- 【Metasploit魔鬼训练营--实践笔记】4.2.3 SQL 注入漏洞探测
- 分布式服务框架-原理与实践:13---服务多版本-学习笔记
- 程序设计基石与实践系列之成为一名Top的C语言程序员
- 从实践中学习Oracle SQL笔记
- 【Linux网络编程笔记】TCP短连接产生大量TIME_WAIT导致无法对外建立新TCP连接的原因及解决方法—实践篇
- 添加好友“盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛(重现赛)
- Flex企业应用开发实践学习笔记(七)——Flex Application
- 机器学习工程实践笔记
- 【学习笔记javascript设计模式与开发实践(享元模式)----12】
- 2019春季PAT考试甲级答案
- 《js高级程序设计》之最佳实践(笔记)
- 【javascript高级程序设计笔记】第六章OOP
- 学习笔记——Maven实战(四)基于Maven的持续集成实践
- C++程序设计语言特别版 学习笔记(0)
- JavaScript高级程序设计(第3版)阅读笔记第01天-js简介