博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
老年玩家每日水题(完结)
阅读量:5345 次
发布时间:2019-06-15

本文共 18981 字,大约阅读时间需要 63 分钟。

先定一个小目标:

51nod:基础题(5/5)1级题(5/5)2级题(5/5)3级题(5/5)4级题(5/5)

  • 2017年10月23日

51nod1264

#include
#include
using namespace std;const double eps = 1e-8;class Point{public: double x, y; Point(double a=0, double b=0):x(a), y(b){}};int main(){ int T; cin>>T; while(T--) { Point p[5]; for(int i=0; i<4; ++i) cin>>p[i].x>>p[i].y; double v1 = (p[1].x-p[0].x)*(p[1].y-p[2].y)-(p[1].y-p[0].y)*(p[1].x-p[2].x);//p10 x p12 double v2 = (p[1].x-p[0].x)*(p[1].y-p[3].y)-(p[1].y-p[0].y)*(p[1].x-p[3].x);//p10 x p13 double v3 = (p[3].x-p[2].x)*(p[3].y-p[0].y)-(p[3].y-p[2].y)*(p[3].x-p[0].x);//p23 x p20 double v4 = (p[3].x-p[2].x)*(p[3].y-p[1].y)-(p[3].y-p[2].y)*(p[3].x-p[1].x);//p23 x p21 if((v1*v2<=0) && (v3*v4<=0)) cout<<"Yes"<
View Code

 51nod1212

#include
#include
#define LL long longusing namespace std;const LL maxn = 1e3+3, INF = 2e9+7;int n, m;double grap[maxn][maxn];LL mst(){ LL res = 0; int dis[maxn]; bool vis[maxn]; for(int i=0; i<=n; ++i) { dis[i] = INF; vis[i]=false; } dis[1]=0; int u=1; for(int i=1; i<=n; ++i) { LL MinDis = INF; int v = u; for(int i=1; i<=n; ++i) { //cout<
<<" "; if(!vis[i] && MinDis>dis[i]) { MinDis = dis[i]; v=i; } } vis[v]=true; u=v; //cout<
grap[u][i]) { dis[i] = grap[u][i]; } } } return res;}int main(){ cin>>n>>m; for(int i=0; i<=n; ++i) for(int j=0; j<=n; ++j) { if(i==j) grap[i][j] = 0; else grap[i][j]=INF; } int u, v; double c; for(int i=0; i
>u>>v>>c; grap[u][v]=min(grap[u][v], c); grap[v][u]=min(grap[v][u], c); } cout<
<
View Code
  •  2017年10月24日

51nod1183

#include
#include
#include
using namespace std;const int maxn = 1e3+3, INF = 2e9+7;string a, b;int dp[maxn][maxn];int main(){ while(cin>>a>>b) { int la=a.size(), lb=b.size(); for(int i=0; i
View Code

 51nod1181

#include
#define LL long longusing namespace std;const int maxn = 1e7+6;LL prime[maxn] = {
0}, num_prime=0;int isNotPrime[maxn] = {
1, 1};int main(){ LL n; cin>>n; for(LL i=0; i
=n && !isNotPrime[num_prime]) { cout<
<
View Code

51nod1079

#include
#define int long longusing namespace std;int Extended_Euclid(int a, int b, int &x, int &y){ int d; if(b==0) { x=1, y=0; return a; } d=Extended_Euclid(b, a%b, y, x); y-=a/b*x; return d;}int Chinese_Remainder(int a[], int w[], int len){ int i, d, x, y, m, n=1, ret=0; for(i=0; i
>n) { for(int i=0; i
>w[i]>>a[i]; cout<
View Code
  •  2017年10月25日

51nod1305

#include
#include
#include
#include
#define int long longusing namespace std;vector
a;int fun(vector
& a){ sort(a.begin(), a.end()); int sum=0, tmp=0, la=a.size(); for(int i=0; i
>n; for(int i=0; i
>t; a.push_back(t); } cout<
<
View Code
#include
#include
#define int long longusing namespace std;main(){ int n, t; cin>>n; int ans=0, two=0; for(int i=1; i<=n; ++i)//只有 1, 2 会对结果产生影响 { cin>>t; if(t==1) { ans+=n-1; } else if(t==2) { ans+=two; two++; } } cout<
<
View Code
  •  2017年10月28日

51nod1289

#include
#include
#include
#include
using namespace std;stack
Stack;int main(){ int n; cin>>n; int cnt=n; for(int i=0; i
>a>>b; if(b==1) Stack.push(a); else { while(!Stack.empty()) { if(a>Stack.top()) { cnt--; Stack.pop(); } else { cnt--; break; } } } } cout<
<
View Code

51nod1283

#include
#include
#define LL long longusing namespace std;int main(){ LL s; cin>>s; LL a=sqrt(s); for(int i=a; i<=s; ++i) { if(s%i==0) { cout<<2*(i+s/i)<
View Code

51nod1182

#include
#include
#include
#define LL long longusing namespace std;int sum[100];int main(){ memset(sum, 0, sizeof(sum)); string str; cin>>str; for(int i=0; i
='a'; --i) { ans+=(sum[i]*(i+1-'a')); } cout<
<
View Code
  •  2017年10月29日

51nod1091

#include
#include
#include
#define int long longusing namespace std;class Line{public: int x, y; Line(int a, int b):x(a), y(b) { } bool operator < (const Line& l) { if(x==l.x) return y
Lines;main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; int x, y; cin>>n; for(int i=0; i
>x>>y; Lines.push_back(Line(x, y)); } sort(Lines.begin(), Lines.end()); int len = Lines.size(); int ans=0, pre=Lines[0].y; for(int i=1; i
pre) { ans = max(ans, pre-Lines[i].x); pre=Lines[i].y; } else { ans = max(ans, Lines[i].y-Lines[i].x); } } cout<
<
View Code

 51nod1873

#include 
#include
#include
#include
#include
#define INF 1E9using namespace std;struct BigNum{ int len; int num[10000]; int point; BigNum() { len=1; point=0; memset(num,0,sizeof(num)); }};bool input(BigNum &a){ string s; if(cin>>s) { memset(a.num,0,sizeof(a.num)); int t=0,i; a.len=s.size(); a.point=0; for(i=s.size()-1;i>=0;i--) { if(s[i]=='.'){a.len--;a.point=t;continue;} a.num[t++]=s[i]-'0'; } return 1; } else return 0;}void output(BigNum &a){ int i,j=0,flag; for(i=0;i
=0;i--) { cout<
= 10) { c.num[i+j+1] += (int)c.num[i+j]/10; c.num[i+j] %= 10; } } c.point=a.point+b.point; len = a.len+b.len; while(c.num[len-1] == 0 && len > 1&&len>c.point) len--; if(c.num[len]) len++; c.len = len; return c;}BigNum a;int b;int main(){ while(input(a)&&~scanf("%d",&b)) { BigNum ans; if(b==0){cout<<1<
View Code

51nod1413

#include
using namespace std;int main(){ string str; cin>>str; int ans=0; for(int i=0; i
View Code

 51nod1432

#include
#include
#include
#define int long longusing namespace std;const int maxn = 10005;int Weight[maxn];main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin>>n>>m; for(int i=0; i
>Weight[i]; } int cnt=0; sort(Weight, Weight+n); int pre=0, las=n-1; while(pre<=las) { if(pre==las) { cnt++; break; } if(Weight[pre] + Weight[las] <= m) { pre++; las--; cnt++; } else { while(las>pre && (Weight[pre] + Weight[las] > m)) { las--; cnt++; } pre++; las--; cnt++; } } cout<
<
View Code

51nod1428

#include
#include
#include
#include
#include
#include
#define int long longusing namespace std;const int maxn = 10004;class Line{public: int s, f; Line(int a=0, int b=0):s(a), f(b) { } bool operator < (const Line& l) const { if(this->f==l.f) return this->s>l.s; return this->f>l.f; }};vector
lines;priority_queue
PQ;bool vis[maxn];bool cmp(Line& a, Line& b){ if(a.s == b.s) return a.f
>n; for(int i=0; i
>s>>f; if(s>f) swap(s, f); lines.push_back(Line(s, f)); } sort(lines.begin(), lines.end(), cmp); int len = lines.size(); PQ.push(lines[0]); //cout<<"push: "<
<<", "<
<
View Code
  •  2017年10月30日

51nod1315

#include
#include
#include
#include
#define int long longusing namespace std;const int maxn = 2e9+9;int binary[50];bool vis[50];int nums[50];int GetBinary(){ memset(binary, 0, sizeof(binary)); int val=1, i=0; while(val<=maxn) { binary[i]=val; i++; val<<=1; } return i;}main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int sum=GetBinary(); memset(vis, false, sizeof(vis)); memset(nums, 0, sizeof(nums)); int n, x, t, maxs=0; cin>>n>>x; for(int i=0; i
>t; if((t|x)<=x) for(int i=0; i
View Code

 51nod1636

#include
#include
#include
#include
#define int long longusing namespace std;const int maxn = 105, maxm = 105, maxk = 200;class Lesson{public: int a, b, c; Lesson(int x=0, int y=0, int z=0):a(x), b(y), c(z) { } bool operator < (const Lesson& l) const { return this->c
lessons;int dp[maxn][maxm][maxk];main(){ int n, m, k; cin>>n>>m>>k; int a, b, c; for(int i=1; i<=m; ++i) { cin>>a>>b>>c; lessons.push_back(Lesson(a, b, c)); } sort(lessons.begin(), lessons.end()); memset(dp, -1, sizeof(dp)); for(int i=0; i
= lessons[q].a && p-k <= lessons[q].b && dp[i-1][q][p-k-lessons[q].a]!=-1) { dp[i][j][p-lessons[j].a]=max(dp[i][j][p-lessons[j].a], dp[i-1][q][p-k-lessons[q].a] + p); } if(p%k==0 && p/k >= lessons[q].a && p/k<=lessons[q].b && dp[i-1][q][p/k-lessons[q].a]!=-1) { dp[i][j][p-lessons[j].a]=max(dp[i][j][p-lessons[j].a], dp[i-1][q][p/k-lessons[q].a] + p); } } } } } int ans = 0; for(int i=0; i
View Code
  •  2017年10月31日

51nod1875

#include
#define int long longusing namespace std;int ans[20]={
0};int deal(int x){ for(int i=1; i<=1e7; ++i) { int all = 2*x; int s = 0; while(all>x) { s += (s==0?0:-1); s = (s+i)%all; if(s<=x && s!=0) break; all--; if(all == x) return i; } }}void init(){ ans[1]=1; for(int i=1; i<15; ++i) ans[i] = deal(i);}main(){ init(); int G; while(cin>>G && G!=0) { cout<
<
View Code

51nod1572

#include
#include
#include
#include
using namespace std;const int maxn = 1e3+5;class Op{public: int dir, len; Op(int a=0, int b=0):dir(a), len(b) { }};char grap[maxn][maxn];int limit[maxn][maxn][5];//每个点四个方向的最大值int dir[4][2] = {
{-1, 0}, {
1, 0}, {
0, 1}, {
0, -1} };//上下右左int word[30][3];vector
ops;bool check(int w, int n, int m){ int x=word[w][1], y=word[w][2]; for(int i=0; i
= limit[x][y][item.dir]) return false; x+=item.len * dir[item.dir][0], y+=item.len * dir[item.dir][1]; if(x<0 || y<0 || x>n || y>m || grap[x][y]=='#') return false; } return true;}main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); memset(word, -1, sizeof(word)); int n, m, k, pre=0; cin>>n>>m; for(int i=0; i
>grap[i]; pre=0; for(int j=0; j
='A' && grap[i][j]<='Z') { word[int(grap[i][j]-'A')][0] = 1; word[int(grap[i][j]-'A')][1] = i; word[int(grap[i][j]-'A')][2] = j; } if(grap[i][j] == '#') { pre=j; } else { limit[i][j][3]=abs(j-pre); } } pre=0; for(int j=m-1; j>=0; --j) { if(grap[i][j] == '#') { pre=j; } else { limit[i][j][2]=abs(j-pre); } } } for(int j=0; j
=0; --i) { if(grap[i][j] == '#') { pre=i; } else { limit[i][j][1]=abs(i-pre); } } } cin>>k; char d; int l; for(int i=0; i
>d>>l; switch(d) { case 'N':ops.push_back(Op(0, l));break; case 'S':ops.push_back(Op(1, l));break; case 'E':ops.push_back(Op(2, l));break; case 'W':ops.push_back(Op(3, l));break; } } bool can = false; for(int i=0; i<26; ++i) { if(word[i][0]!=-1) { if(check(i, n, m)) { cout<
View Code

51nod1562

#include
#include
#include
#include
#include
#define int long long#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1;using namespace std;const int maxn = 200005;class Point{public: int LeftPos, RightPos, LeftLen; Point(int lp=0, int rp=0, int ll=0):LeftPos(lp),RightPos(rp),LeftLen(ll) { }};vector
is;vector
cs;int wline[maxn], hline[maxn];Point wpoint[maxn], hpoint[maxn];main(){ int w, h, n, x; char op; memset(wline, 0, sizeof(wline)); memset(hline, 0, sizeof(hline)); cin>>w>>h>>n; for(int i=0; i
>op>>x; cs.push_back(op); is.push_back(x); if(op=='H') { hline[x]=1; } else { wline[x]=1; } } hline[0]=wline[0]=hline[h]=wline[w]=1; int maxh=0, maxw=0; for(int i=0, pre=0; i<=w; ++i) { if(wline[i]) { maxw=max(maxw, i-pre); wpoint[pre].RightPos=i; wpoint[i]=Point(pre, i, i-pre); pre=i; } } for(int i=0, pre=0; i<=h; ++i) { if(hline[i]) { maxh=max(maxh, i-pre); hpoint[pre].RightPos=i; hpoint[i]=Point(pre, i, i-pre); pre=i; } } //cout<<"maxw: "<
<<"maxh: "<
<
ans; for(int i=n-1; i>=0; --i) { ans.push(maxw*maxh); if(cs[i]=='H') { tmp = hpoint[is[i]]; hpoint[tmp.LeftPos].RightPos = tmp.RightPos; hpoint[tmp.RightPos].LeftPos = tmp.LeftPos; hpoint[tmp.RightPos].LeftLen += tmp.LeftLen; maxh = max(maxh, hpoint[tmp.RightPos].LeftLen); } else { tmp = wpoint[is[i]]; wpoint[tmp.LeftPos].RightPos = tmp.RightPos; wpoint[tmp.RightPos].LeftPos = tmp.LeftPos; wpoint[tmp.RightPos].LeftLen += tmp.LeftLen; maxw = max(maxw, wpoint[tmp.RightPos].LeftLen); } } //cout<
<<" ans "<
View Code
  •  2017年11月1日

51nod1785

#include
#include
#include
#include
using namespace std;int n,sum,p,num,k,now,cnt,s[105],a[1000050];int read(){ int x=0,f=1;char c=getchar(); while(c<'0'||c>'9'){
if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f;}int main(){ n=read();k=read(); while(n--) { p=read(); if(p==1) { num=read(); a[++cnt]=num; if(now==k)sum=sum-a[cnt-k]+num,s[a[cnt-k]]--; else now++,sum+=num; s[num]++; } else if(p==2) { printf("%.2lf\n",floor((double)sum/now)); //printf("debug: %d, %d\n", sum, now); } else if(p==3) { double w=(double)sum/now,ans=0; for(int i=cnt-now+1;i<=cnt;i++)ans+=((double)a[i]-w)*((double)a[i]-w); printf("%.2lf\n",ans/now); } else { if(now%2) { int pos=now/2+1,ans=0; for(int i=0;i<=100;i++) { ans+=s[i]; if(ans>=pos) { printf("%.2lf\n",(double)i); break; } } } else { int pos1=now/2,pos2=now/2+1,st=-1,ed=-1,ans=0; for(int i=0;i<=100;i++) { ans+=s[i]; if(ans>=pos1&&st==-1)st=i; if(ans>=pos2&&ed==-1)ed=i; if(st!=-1&&ed!=-1) { printf("%.2lf\n",(double)(st+ed)/2); break; } } } } } return 0;}
View Code

 51nod1637

#include
#include
using namespace std;const int maxn = 1e5+5;char str[maxn];int main(){ int n, k; scanf("%d%d",&n,&k); getchar(); gets(str+1); bool can=false; while(k) { for(int i=1; i
View Code
  •  2017年11月2日

51nod1829

#include
#define int long longusing namespace std;const int mod = 1e9+7, maxn = 1e6+6;int c[maxn];int Pow(int x, int n){ int res=1; x=x%mod; n=n%(mod-1); while(n) { if(n&1) res=res*x%mod; n>>=1; x=x*x%mod; } return res;}int com(int n, int m){ if(n>m) return n; return c[m]*Pow(c[n]*c[m-n]%mod, mod-2)%mod;}void init(){ c[0]=1; for(int i=1; i
>n>>m; int ans=0, k=1; for(int i=m; i>=1; --i) { ans=(ans+(com(m-i, m)%mod + mod)%mod*(Pow(i, n)%mod*k + mod)%mod)%mod; k=0-k; } cout<
<
View Code

 51nod1832

#include
#include
#include
#define int long long#define L 1#define R 2using namespace std;const int maxn = 1e4+5;int r[maxn], a[maxn], b[maxn], cnt=0;int ans[maxn];void dfs(int al, int ar, int bl, int br){ if(al==ar) return; al++, br--; int p = r[a[al]]; if(p==br) { cnt++; dfs(al, ar, bl, br); return; } int len = p-bl+1; dfs(al, al+len-1, bl, bl+len-1); dfs(al+len, ar, bl+len, br);}main(){ memset(r, 0, sizeof(r)); memset(ans, 0, sizeof(ans)); int n; cin>>n; for(int i=1; i<=n; ++i) { cin>>a[i]; } for(int i=1; i<=n; ++i) { cin>>b[i]; r[b[i]]=i; } dfs(1, n, 1, n); ans[0]=1; int len=1; while(cnt) { for(int i=0; i
=0; --i) cout<
View Code

 51nod1791

#include
#include
#include
#include
#include
using namespace std;#define int long longstring str;stack
s;int T;int ans,num[1000505];main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>T; while(T--) { //memset(num, 0, sizeof(num)); cin>>str; ans=0; while(!s.empty()) s.pop(); int len=str.size(); for(int i=0; i
View Code

 51nod1717

#include
#define int long longusing namespace std;main(){ int n; while(cin>>n) { int cnt=n; for(int i=1; i*i<=n; ++i) { cnt--; } cout<
<
View Code

 

转载于:https://www.cnblogs.com/xiepingfu/p/7717212.html

你可能感兴趣的文章
单臂路由
查看>>
css遮罩层
查看>>
shell语法 04-Linux文本处理-sed
查看>>
力扣——快乐数
查看>>
设置代理
查看>>
错误变惊喜,10个有趣的404页面设计(转)
查看>>
[转]linux awk命令详解
查看>>
值得推荐的C/C++框架和库
查看>>
组队赛第二场:字符串哈希+DP
查看>>
atitit.团队建设--要不要招技术储备人才的问题
查看>>
工作笔记 7.21-7.25
查看>>
UVA 11769 All Souls Night 的三维凸包要求的表面面积
查看>>
Matlab画图-非常具体,非常全面
查看>>
TCP/IP、Http、Socket的差别
查看>>
BCD码、十六进制与十进制互转
查看>>
每个测试都该知道的测试用例方法及细节设计
查看>>
Dom实例:数据自增、搜索框及跑马灯
查看>>
软件工程——理论、方法与实践 之 软件工程中的形式化方法
查看>>
Linux三剑客awk的应用对比案例详解
查看>>
ubuntu bash提示找不到文件或目录
查看>>