当前位置: 代码迷 >> 综合 >> ACM Greater New York 2017
  详细解决方案

ACM Greater New York 2017

热度:73   发布时间:2023-11-02 21:56:33.0
  •  A. Chanukah Challenge 题库链接

    • 通过率: 99.38 %
    • 通过人数: 161
    • 简单签到题,去旅行点蜡烛,第一天点一根蜡烛,第二天点两根蜡烛,第三天点三根蜡烛,以此类推。另外每天还需要一根引火的蜡烛。
    • #include<iostream>
      #include<cstdio>
      #include<cmath>
      using namespace std;
      int main(){int p,k,n;scanf("%d",&p);while(p--){scanf("%d%d",&k,&n);printf("%d %d\n",k,n+n*(n+1)/2);}return 0;
      }

       

  •  B. Sum Squared Digits Function 题库链接

    • 通过率: 99.26 %
    • 通过人数: 134
    • 简单模拟题,利用短除法得到n在b进制下的每一位,对每一位的平方求和,即答案。
    • #include<iostream>
      #include<cstdio>
      #include<cmath>
      using namespace std;
      int main(){int p,k,b,n;scanf("%d",&p);while(p--){scanf("%d%d%d",&k,&b,&n);long long ans=0;int a;while(n){a=n%b;ans+=a*a;n/=b;}printf("%d %lld\n",k,ans);}return 0;
      }

       

  •  C. Capsules 题库链接

    • 通过率: 66.67 %
    • 通过人数: 8
  •  D. Pavers 题库链接

    • 通过率: 82.35 %
    • 通过人数: 14
  •  E. Best Rational Approximation 题库链接

    • 通过率: 85.37 %
    • 通过人数: 70
    •  
    • //法里数列 
      #include<iostream>
      #include<algorithm>
      #include<cmath>
      #include<cstdio>
      using namespace std;
      int main()
      {int p;int k,m;double x;scanf("%d",&p);while (p--){scanf("%d%d%lf",&k,&m,&x);	int x1=0,y1=1,x2=1,y2=1;int x3,y3;while (1){x3=x1+x2;y3=y1+y2;int gc=__gcd(x3,y3);x3/=gc;y3/=gc;if (y3>m)break;if ((1.0*x3/y3)<=x){y1=y3;x1=x3;}else{x2=x3;y2=y3;}		}printf("%d ",k);if (fabs(1.0*x1/y1-x)>fabs(1.0*x2/y2-x))printf("%d/%d\n",x2,y2);elseprintf("%d/%d\n",x1,y1);}return 0;
      }

       

  •  F. The Components Game 题库链接

    • 通过率: 40 %
    • 通过人数: 2
  •  G. Social Resistance 题库链接

    • 通过率: 100 %
    • 通过人数: 1
  •  H. Triangle to Hexagon 题库链接

    • 通过率: 86.49 %
    • 通过人数: 32
    • //套计算几何模板 
      //https://www.lucien.ink/archives/200/#directory065281254978648458
      #include <bits/stdc++.h>double eps = 1e-9;int cmp(double a, double b) {if (fabs(a - b) < eps) return 0;return a < b ? -1 : 1;
      }struct Point { // 点double x, y;Point(double x = 0, double y = 0):x(x), y(y) {}bool operator != (const Point &tmp) const {return (cmp(x, tmp.x) != 0 || cmp(y, tmp.y) != 0);}double dist(const Point point) const {return sqrt((x - point.x) * (x - point.x) + (y - point.y) * (y - point.y));}
      } a, b, c, e, f, g, h, i, j, k, m, n, p;struct Line { // 线Point u, v;Line(Point a = 0, Point b = 0):u(a), v(b) {}Point intersection(const Line &line) const {Point ret = u;double tmp = ((u.x - line.u.x) * (line.u.y - line.v.y) - (u.y - line.u.y) * (line.u.x - line.v.x))/ ((u.x - v.x) * (line.u.y - line.v.y) - (u.y - v.y) * (line.u.x - line.v.x));ret.x += (v.x - u.x) * tmp;ret.y += (v.y - u.y) * tmp;return ret;}
      };struct Triangle { // 三角形Point a, b, c;Triangle(Point a = 0, Point b = 0, Point c = 0):a(a), b(b), c(c) {}Point outCenter() {Line u, v;u.u.x = (a.x + b.x) / 2;u.u.y = (a.y + b.y) / 2;u.v.x = u.u.x - a.y + b.y;u.v.y = u.u.y + a.x - b.x;v.u.x = (a.x + c.x) / 2;v.u.y = (a.y + c.y) / 2;v.v.x = v.u.x - a.y + c.y;v.v.y = v.u.y + a.x - c.x;return u.intersection(v);}Point inCenter() {Point ua, ub, va, vb;double m, n;ua = a;m = atan2(b.y - a.y, b.x - a.x);n = atan2(c.y - a.y, c.x - a.x);ub.x = ua.x + cos((m + n) / 2.0);ub.y = ua.y + sin((m + n) / 2.0);va = b;m = atan2(a.y - b.y, a.x - b.x);n = atan2(c.y - b.y, c.x - b.x);vb.x = va.x + cos((m + n) / 2.0);vb.y = va.y + sin((m + n) / 2.0);return Line(ua, ub).intersection({va, vb});}};struct Circle { // 圆Point center;double r;Circle(Point center = 0, double r = 0):center(center), r(r) {}std::pair<Point, Point> intersection(const Line &line) const {Point p = center, p1, p2;double tmp;p.x += line.u.y - line.v.y;p.y += line.v.x - line.u.x;p = line.intersection({p, center});tmp = sqrt(r * r - p.dist(center) * p.dist(center)) / line.u.dist(line.v);p1.x = p.x + (line.v.x - line.u.x) * tmp;p1.y = p.y + (line.v.y - line.u.y) * tmp;p2.x = p.x - (line.v.x - line.u.x) * tmp;p2.y = p.y - (line.v.y - line.u.y) * tmp;return std::make_pair(p1, p2);};
      } o;void read() {b.y = a.x = a.y = 0.0;scanf("%*d%lf%lf%lf", &b.x, &c.x, &c.y);
      }Point myIntersection(Circle circle, Line line) {auto tmp = circle.intersection(line);return (tmp.first != line.u && tmp.first != line.v) ? tmp.first : tmp.second;
      }void init() {o.center = Triangle(a, b, c).outCenter();o.r = o.center.dist(a);i = Triangle(a, b, c).inCenter();n = myIntersection(o, Line(b, i));m = myIntersection(o, Line(a, i));p = myIntersection(o, Line(c, i));e = Line(a, b).intersection(Line(p, n));f = Line(a, c).intersection(Line(p, n));g = Line(m, n).intersection(Line(a, c));h = Line(m, n).intersection(Line(b, c));j = Line(p, m).intersection(Line(b, c));k = Line(a, b).intersection(Line(p, m));
      }void print(Point a, Point b) {printf(" %.4f", a.dist(b));
      }void out() {print(e, f);print(f, g);print(g, h);print(h, j);print(j, k);print(k, e);putchar('\n');
      }int main() {int t;scanf("%d", &t);for (int i = 1; i <= t; i++) printf("%d", i), read(), init(), out();return 0;
      }

       

  •  I. Sumdoku 题库链接

    • 通过率: 100 %
    • 通过人数: 8
  •  J. Toys 题库链接

    • 通过率: 100 %
    • 通过人数: 2
  相关解决方案