Day2

来源:互联网 发布:开淘宝店做代理好不好 编辑:程序博客网 时间:2024/06/05 15:09

T1 

分析模拟一下切蛋糕过程,倒叙模拟后发现,这个切的动作想要停止,就必须最后变成二分之一,所以就可以推出一个斐波那契数列。

模拟,当n or m模一个斐波那契数列中的一项成立时,就满足了不停切的要求从而得到题解。


代码如下:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
ll ans,ans1,ans2;
ll a,b;
ll f[53];
int main()
{
 freopen("cut.in","r",stdin);
 freopen("cut.out","w",stdout);
 scanf("%d%d",&a,&b);
 f[1] = 1;
 f[2] = 1;
 for(int i = 3;i <= 53;i++)
 {
  f[i] = f[i-1] + f[i-2];
 }
 for(int i = 53;i >= 1;i--)
 {
//  printf("%d %lld",a,f[i]);
  if(a % f[i] == 0)
  {
   ans1 = (a - a/f[i])*b;
   break;
  }
 }
 for(int i = 53;i >= 1;i--)
 {
  if(b % f[i] == 0)
  {
   ans2 = (b - b/f[i])*a;
   break;
  }
 }
 ans = max(ans1,ans2);
 cout<<ans;
 fclose(stdin);
 fclose(stdout);
 return 0;
}

T2 :

这题,通过一个玄学的想法我们可以发现,当前结点对于原点所包涵的白格数量一定是x/y下取整,那么黑格数就是x*y - x/y,所以我们就可以进行一种很玄学的操作就是加一个点所包含的白格数和黑格数,再减去下一个点所包含的白格数和黑格数,当然题目保证给的数满足逆时针方向就是相邻两个节点必然y值相等。

玄学。

最后取绝对值。

代码如下:

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
int n;
long long X[120000], Y[120000], ansx, ansy;
void solve(long long x, long long y, int c) {
 long long p = (x >> 1) * (y >> 1) + ((x + 1) >> 1) * ((y + 1) >> 1);
 long long q = x * y - p;
 ansx += p * c;
 ansy += q * c;
}
int main(){
 freopen("bw.in", "r", stdin);
 freopen("bw.out", "w", stdout);
 scanf("%d", &n);
 for(int i = 1; i <= n; i++) scanf("%lld%lld", &X[i], &Y[i]);
 X[n + 1] = X[1];Y[n + 1] = Y[1];
 for(int i = 1; i <= n; i++) {
  if (Y[i] == Y[i + 1]) {
   solve(X[i], Y[i], 1);
   solve(X[i + 1], Y[i + 1], -1);
  }
 }
 printf("%lld %lld\n",ansx, ansy);
}

T3

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
int n;
long long X[120000], Y[120000], ansx, ansy;
void solve(long long x, long long y, int c) {
 long long p = (x >> 1) * (y >> 1) + ((x + 1) >> 1) * ((y + 1) >> 1);
 long long q = x * y - p;
 ansx += p * c;
 ansy += q * c;
}
int main(){
 freopen("bw.in", "r", stdin);
 freopen("bw.out", "w", stdout);
 scanf("%d", &n);
 for(int i = 1; i <= n; i++) scanf("%lld%lld", &X[i], &Y[i]);
 X[n + 1] = X[1];Y[n + 1] = Y[1];
 for(int i = 1; i <= n; i++) {
  if (Y[i] == Y[i + 1]) {
   solve(X[i], Y[i], 1);
   solve(X[i + 1], Y[i + 1], -1);
  }
 }
 printf("%lld %lld\n",ansx, ansy);
}

T3

没时间解释了,快上车

代码如下:

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cassert>
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define drep(i,a,b) for (int i=a;i>=b;i--)
#define INF int(1e8)
#define LL long long
#define pb push_back
#define mp make_pair
#define clr(a) memset(a,0,sizeof(a));
using namespace std;
const double eps=1e-10;
const int N=1000;
int n;
double limitx,limity;
struct point
{
 double x,y;
 point() {}
 point(double _x,double _y) : x(_x),y(_y) {}
 void print(){printf("%.6lf %.6lf\n",x,y);}
};
vector<point> can;
int operator ==(point a,point b)
{
 return fabs(a.x-b.x)<=eps && fabs(a.y-b.y)<=eps;
}
struct Line
{
 double a,b,c;
 Line() {}
 Line(point p,point q)
 {
  a=b=c=0;
  if (p==q) assert(0);
  if (fabs(p.y-q.y)<=eps)
  {
   a=0;b=1;c=-p.y;
   return;
  }
  if (fabs(p.x-q.x)<=eps)
  {
   a=1;b=0;c=-p.x;
   return;
  }
  a=1;
  b=(q.x-p.x)/(p.y-q.y);
  c=-p.x-b*p.y;
 }
 void print(){printf("%.4lf %.4lf %.4lf\n",a,b,c);}
};
point operator *(Line a,Line b)
{
 if (fabs(a.a*b.b-a.b*b.a)<=eps) return point(limitx-2.*eps,limity-2.*eps);
 return point(   ( a.b*b.c-a.c*b.b)/(a.a*b.b-a.b*b.a) , ( a.a*b.c-a.c*b.a)/(a.b*b.a-a.a*b.b));
}
struct Circle
{
 double x,y,r;
 point o;
 Circle() {}
 Circle(double _x,double _y,double _r) : x(_x),y(_y),r(_r) {o=point(x,y);}
 void read(){scanf("%lf%lf%lf",&x,&y,&r);o=point(x,y);}
 void print(){printf("%.5lf %.5lf %.5lf\n",x,y,r);}
};
Circle cir[N];
point Rot(point a,point center,double ang)
{
 return point((a.x-center.x)*cos(ang)-(a.y-center.y)*sin(ang)+center.x,(a.x-center.x)*sin(ang)+(a.y-center.y)*cos(ang)+center.y);
}
Circle Rot(Circle a,point center,double ang)
{
 a.o=Rot(a.o,center,ang);
 a.x=a.o.x;a.y=a.o.y;
 return a;
}
double Dis(point a,point b)
{
 return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double Angle(point a,point b)
{
 return atan2(b.y-a.y,b.x-a.x);
}
pair<Line,Line> Tangent(Circle x,Circle y)
{
 double ang=Angle(x.o,y.o);
 y=Rot(y,x.o, -ang );
 double dis=Dis(x.o,y.o);
 point mid=point(x.o.x+dis/(x.r+y.r)*x.r,x.o.y);
 dis=dis/(x.r+y.r)*x.r;
 double dltx=x.r*x.r/dis,dlty=sqrt(x.r*x.r-dltx*dltx);
 point Up=point(x.o.x+dltx,x.o.y+dlty),Down=point(x.o.x+dltx,x.o.y-dlty);
 if (Up==mid)
 {
  Up.y+=1.;
  Down.y-=1.;
 }
 Up=Rot(Up,x.o,ang); Down=Rot(Down,x.o,ang); mid=Rot(mid,x.o,ang);
 can.pb(mid);
 return mp( Line(Up,mid), Line(Down,mid) );
}
pair<double,double> Tangent(Circle x,point y)
{
 double ang=Angle(x.o,y);
 y=Rot(y,x.o,-ang );
 double dis=Dis(x.o,y);
 point mid=y;
 double dltx=x.r*x.r/dis,dlty=sqrt(x.r*x.r-dltx*dltx);
 
 point Up=point(x.o.x+dltx,x.o.y+dlty),Down=point(x.o.x+dltx,x.o.y-dlty);
 if (Up==mid)
 {
  Up.y+=1.;
  Down.y-=1.;
 }
 Up=Rot(Up,x.o,ang); Down=Rot(Down,x.o,ang); mid=Rot(mid,x.o,ang);
 return mp( Angle(mid,Up), Angle(mid,Down) );
}
int In2(double x,double l,double r)
{
 if (x-M_PI*2.>l+1e-6 && x-M_PI*2.<r-1e-6) return 1;
 if (x>=l+eps && x<=r-eps) return 1;
 if (x+M_PI*2.>l+1e-6 && x+M_PI*2.<r-1e-6) return 1;
 return 0;
}
int In(double x,double l,double r)
{
 if (x>=l+eps && x<=r-eps) return 1;
 return 0;
}
int In(point x,Circle c)
{
 if (Dis(x,c.o)<=c.r-eps*3.) return 1;
 return 0;
}
pair<double,double> seg[N];
int check(point x)
{
 if (!(In(x.x,0,limitx) && In(x.y,0,limity))) return 0;
 rep(i,1,n) if (In(x,cir[i])) return 0;
 rep(i,1,n) seg[i]=Tangent(cir[i],x);
 rep(i,1,n) if (seg[i].first>seg[i].second) seg[i].first-=2.*M_PI;
 rep(i,1,n)
  rep(j,1,n)
  {
   if (i==j) continue;
   if (In2(seg[i].first,seg[j].first,seg[j].second) || In2(seg[i].second,seg[j].first,seg[j].second))
   {
    return 0;
   }
  }
 return 1;
}
vector<Line> line;
point res;
int cnt;
int main()
{
 freopen("cookie.in", "r", stdin);
 freopen("cookie.out", "w", stdout);
 scanf("%d%lf%lf",&n,&limitx,&limity);
 rep(i,1,n) cir[i].read();
 pair<Line,Line> x=Tangent(cir[1],cir[2]);
 rep(i,1,n) rep(j,i+1,n)
 {
  pair<Line,Line> c=Tangent(cir[i],cir[j]);
  line.pb(c.first);line.pb(c.second);
 }
 for(int i=0;i<line.size();i++)
  for (int j=0;j<line.size();j++)
   if (i!=j) can.pb(line[i]*line[j]);
 can.pb(point(eps*2,eps*2));
 can.pb(point(eps*2,limity-eps*2));
 can.pb(point(limitx-eps*2,eps*2));
 can.pb(point(limitx-eps*2,limity-eps*2));
 for(int i=0;i<can.size();i++)
  if (check(can[i])) cnt++,res=can[i];
 if (!cnt) puts("No Point");
 else printf("%.15lf %.15lf\n",res.x,res.y);
}

不可做不可做orz

原创粉丝点击