예제 #1
0
 string getHint(string secret, string guess) {
     int n = secret.size();
     vector<int> cnt1(10), cnt2(10);
     int bull = 0;
     for(int i = 0; i < n; i++) {
         char c1 = secret[i], c2 = guess[i];
         if(c1 == c2) {
             bull++;
             cnt1[c1 - '0']--;
             cnt2[c2 - '0']--;
         }
         cnt1[c1 - '0']++;
         cnt2[c2 - '0']++;
     }
     int cow = 0;
     for(int i = 0; i < 10; i++) {
         cow += min(cnt1[i], cnt2[i]);
     }
     return to_string(bull) + "A" +  to_string(cow) + "B";
 }
예제 #2
0
vec_type Cylinder<base_tt>::TestContour(const contour_t &cnt, VecContour<> *subcont, Vector_3 *subcenter) const{
  if(cnt.GetNPoints()==0)
    return 0;

  Vector_3 ncnt=cnt.GetNormVect();
  ncnt.normalize();
  vec_type coef=ncnt*n;

  if(acccomp(coef,0.)){ // контур параллелен оси циллиндра, его нельзя спроектировать на основание
    Vector_3 k=ncnt%n,b=*(cnt.points_begin());
    Vector_2 k2=::Vector_3to2(k,Vector_3(),x,y),b2=Vector_3to2(b);
    vec_type frac[2];
    Vector_2 surfp[2];
    int tl=base->TestLine(b2,k2,frac,surfp);
    if(tl<=1)
      return 0; // all outside, no intersection
    Plane_3 planes[3];
    planes[0].init(k, Vector_2to3(surfp[0]));
    planes[1].init(-k, Vector_2to3(surfp[1]));
    Polyhedron_3 poly(planes, planes+2, 0);
    return poly.TestContour(cnt, NULL, subcenter);
  }

  // контур проецируется на основание
  Contour_3to2<contour_t> cnt2(cnt,origin,x,y);
  Vector_2 subcenter2;
  vec_type area=base->TestContour(cnt2, NULL, subcenter ? &subcenter2 : NULL);
  area/=fabs(coef);
  if(area!=0 && subcenter){
    Vector_3 b=*(cnt.points_begin()); // начальная вершина контура
    vec_type hc=(b-origin)*n; // ее высота
    Vector_3 c=Vector_2to3(subcenter2)+hc*n; // переводит в 3D на уровне точки b
    Plane_3 pl(ncnt,b); // плоскость контура
    pl.TestRay(c,n,subcenter); // поднимаем в плоскость контура
  }
  return area;
}
예제 #3
0
vec_type Sphere::TestContour(const contour_t &cnt, VecContour<> *subcont, Vector_3 *subcenter) const{

  if(subcenter)
    *subcenter=0;

  Vector_3 nn=cnt.GetNormVect(); // normal to contour
  nn.normalize();
    
  vec_type dist=(*(cnt.points_begin())-center)*nn; // "distance" from center of sphere to contour plane (can be negative)
  vec_type r2=(R*R-dist*dist); // radius^2 of this circle forming by intersection between contour plane and sphere
  if (r2<=0) return 0; // contour plane does not intersect sphere

  Vector_3 c=center+dist*nn; // center of circle 
  Circle C(sqrt(r2),Vector_2());
  Vector_3 ax,ay;
  set_perpendiculars(nn,ax,ay);
  Contour_3to2<contour_t> cnt2(cnt,c,ax,ay);
  Vector_2 subcenter2;
  vec_type area=C.TestContour(cnt2,NULL,subcenter ? &subcenter2 : NULL);
  if(subcenter && area)
    *subcenter=Vector_2to3(subcenter2,c,ax,ay);

  return area;
}