洛谷春季多校第四场
solve | A | B | C | D | E | F | G | H |
3/8 | Ø | √ | √ | √ |
T125998 God J and Ham Sausage
切香肠:用到微积分求球缺,做法:用积分公式
分类讨论;注意浮点运算;
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e5+5; typedef long double db; const db PI=acos(-1.0); const db eps=1e-10; db h,r,d; db VR,SR; db v(db x){return PI*(-x*x*x/3+r*x*x);} db V(db x){ db ans; if(x<r+eps) ans=v(x); else if(x<=h+r+eps) ans=VR/2+(x-r)*SR; else if(x<=h+2*r+eps) ans=VR/2+h*SR+(VR/2-v(h+2*r-x)); else ans=VR+h*SR; return ans; } int main(){ scanf("%Lf %Lf %Lf",&h,&r,&d); VR=4*PI*r*r*r/3; SR=PI*r*r; int len=ceil( (h+2*r)/d-eps ); for(int i=1;i<=len;i++){ printf("%.10Lf\n",V(i*d)-V( (i-1)*d ) ); } // system("pause"); return 0; }
T125995 God J and Eel
模拟;没啥意思记得map可以开二维就行;
#include<bits/stdc++.h> using namespace std; struct node{string s;int t; friend operator<(node a,node b){ return a.t>b.t; } node (string tmp,int k){ s=tmp,t=k; } }; const int N=1e3+5; priority_queue<node>Q[N]; map<string,int>mp[N]; int main(){ int n,m; scanf("%d %d",&n,&m); int a,b,tmp;string s; for(int time=1;time<=m;time++){ int op; scanf("%d",&op); if(op==1){ scanf("%d %d ",&a,&b);cin>>s;scanf("%d",&tmp); Q[a].push(node(s,tmp)); mp[a][s]=tmp; } if(op==2){ scanf("%d",&a); node u=Q[a].top(); while(!Q[a].empty()&&u.t<time)u=Q[a].top(),Q[a].pop(); if(Q[a].empty()){puts("Happy");} else cout<<u.s<<endl; } else { scanf("%d ",&a); cin>>s; if(mp[a][s]>=time)puts("OK"); else puts("GG"); } } system("pause"); return 0; }
T125996 God J and Firm Structure
这题想了挺久的;
题意:给你n割点,删除k割点以后,图不连通,问你最小连边;
k=1;一条链,
k=2; 一个环;
k>2;每个点连出k个边;
确实挺神奇的;
一个图不连通,一定是由最孤立的点决定的,那么删除k个点之后,这个连边最少的孤立点被断开,
要求边最少,所以其他点连边应该也是k;
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int t; scanf("%d",&t); while(t--){ ll n,k; ll ans; scanf("%lld %lld",&n,&k); if(k==1)ans=n-1; else if(k==2)ans=n; else { // ans=(k-1)*n-((k-1)*k/2-1); ans=(long long )(ceil(n*k*1.0/2)); } printf("%lld\n",ans); } // system("pause"); return 0; }
想的太多,做的太少;