您的位置:首页 > 其它

Noip模拟题解题报告

2018-10-17 11:42 197 查看

Pro

第一次AK。

题目链接

Sol

站军姿

算是数学题吧,求出两圆的位置关系,然后余弦定理和扇形面积什么的搞搞就行。

#include<iostream>
#include<cstdio>
#include<cmath>
#define rfile(x) freopen("x.in","r",stdin);
#define wfine(x) freopen("x.out","w",stdout);
using namespace std;

const double pi = 3.14159265358979323846264;
int T , flag;
double x1 , Y1 , r1 , x2 , y2 , r2 , len;

inline double mypow(double x , int y) {
if(!y)
return 1;
double t = mypow(x , y>>1);
if(y&1)
return t*t*x;
return t*t;
}

int jud(double x1 , double Y1 , double r1 , double x2 , double y2 , double r2) {
if(len<r1+r2)
return 0;//相交
else
return 1;
}

void sol(double x1 , double Y1 , double r1 , double x2 , double y2 , double r2) {
len = sqrt(mypow(x1-x2,2)+mypow(Y1-y2,2));
double S1=pi*mypow(r1,2) , S2=pi*mypow(r2,2);
if((r1-r2)>=len) {
printf("%.3lf\n",S1);
return ;
}
if((r2-r1)>=len) {
printf("%.3lf\n",S2);
return ;
}
flag = jud(x1,Y1,r1,x2,y2,r2);
if(flag)
printf("%.3lf\n",S1+S2);
if(!flag) {
double a1 , a2 , s1 , s2;
a1 = 2*acos((r1*r1+len*len-r2*r2)/(2*r1*len));
a2 = 2*acos((r2*r2+len*len-r1*r1)/(2*r2*len));
s1 = r1*r1*a1/2-r1*r1*sin(a1)/2;
s2 = r2*r2*a2/2-r2*r2*sin(a2)/2;
printf("%.3lf\n",S1+S2-s1-s2);
}
}

int main() {
freopen("A.in","r",stdin);
freopen("A.out","w",stdout);
scanf("%d",&T);
while(T--) {
scanf("%lf%lf%lf%lf%lf%lf",&x1,&Y1,&r1,&x2,&y2,&r2);
sol(x1,Y1,r1,x2,y2,r2);
}
return 0;
}

对刚

约瑟夫杀人问题,特别水。

#include<iostream>
#include<cstdio>
using namespace std;

int n , t , vis[200005] , kill , opt , cnt;

int main() {
freopen("B.in","r",stdin);
freopen("B.out","w",stdout);
scanf("%d%d",&n,&t);
while(kill!=n) {
if(vis[opt+1]) {
opt++;
continue;
}
cnt++;
opt++;
if(opt>n) opt-=n;
if(cnt==t) {
cnt = 0;
vis[opt] = vis[opt+n] = 1;
kill++;
}
}
printf("%d",opt);
return 0;
}

隔壁

做USACO的时候刷到过一道比这个难的题。

这个还是比较简单的,最大值很容易求,就是每一行每一列的最小值。

至于最小值,分两部分求,先做行再做列,能放到同一行的尽量放就会使答案更小。

放过就打上标记,然后再做列的部分。

#include<iostream>
#include<cstdio>
using namespace std;

long long n , m , a[1005] , b[1005] , ans1 , ans2 , visa[1005] , visb[1005];
inline long long mymin(long long x , long long y) { return x<y?x:y; }

int main() {
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
scanf("%lld%lld",&n,&m);
for(int i=1; i<=n; i++)
scanf("%lld",&a[i]);
for(int i=1; i<=m; i++)
scanf("%lld",&b[i]);
for(int i=1; i<=n; i++) {
visa[i] = 1;
long long res = 1e9 , pot = 0;
for(long long j=1; j<=m; j++) {
if(b[j]>=a[i]) {
if(b[j]<res&&!visb[j]) {
res = b[j];
pot = j;
}
}
ans2 += mymin(a[i],b[j]);
}
if(res == a[i])
visb[pot] = 1;
ans1 += a[i];
}
for(int i=1; i<=m; i++) {
if(visb[i])
continue;
ans1 += b[i];
}
printf("%lld %lld",ans1,ans2);
return 0;
}
阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: