Exemple #1
0
int main(void)
{
    FILE *fp;
    int cnt = 0;
    char buf[32];

    fp = fopen("words.txt", "r");
    if (!fp) {
        perror("words.txt");
        return 1;
    }

    while (fscanf(fp, "\"%[^\"]\",", buf) != EOF) {
        int i, sum = 0;
        for (i = 0; buf[i] != '\0'; i++) {
            sum += buf[i]-'A'+1;
        }
        cnt += is_triangle(sum);
    }
    fclose(fp);

    printf("%d\n", cnt);

    return 0;
}
Exemple #2
0
int main(void){
	clock_t ini = clock();
	for(int k = 286; !ans; ++k){
		long long a = k, x = 2 * a * a - a;
		if(is_pentagonal(x) && is_triangle(x)) ans = x;
	}
	printf("Time spent: %.3lfs\n", ((double)(clock() - ini))/CLOCKS_PER_SEC);
	printf("Answer: %lld\n", ans);
	return 0;
}
int main(int argc,char *argv[])
{
	int a,b,c;
	int result;
	printf("Please input 3 number as triangle:");
	scanf("%d,%d,%d",&a,&b,&c);
	result = is_triangle(a,b,c);
	if(result == 1)
		printf("a = %d, b = %d, c = %d can found a triangle!\n",a, b, c);
	else if(result == -1)
			printf("Invariable a = %d, b = %d, c = %d!\n",a,b,c);
		else
			printf("a = %d, b = %d, c = %d can not found a triangle!\n",a,b,c);
	return 0;
}
double
wigner3j (const int two_j1, const int two_j2, const int two_j3,
          const int two_m1, const int two_m2, const int two_m3)
/* Returns a single Wigner 3J symbol. Computation is done by
   calculating the family of 3J symbols by J recursion with two_j2 and
   two_j3 fixed, and returning the symbol corresponding to the
   specified value of two_j1. In most cases this will require less
   computation than using M recursion. */
{
  int a = abs (two_j2 - two_j3);
  int b = abs (two_m2 + two_m3);
  int two_jmin = __MAX(a, b);
  int two_jmax = two_j2 + two_j3;
  int dim = 1 + (two_jmax - two_jmin) / 2;
  double buff[__MAX (dim, 1)]; /* Don't want 0 or negative size here. */

  /* Check that |m| <= j */
  if ((abs (two_m1) > two_j1) ||
      (abs (two_m2) > two_j2) ||
      (abs (two_m3) > two_j3))
    return NAN;

  /* Check (j,m) pairs are both integer or both half integer */
  if (__ODD (two_m2 + two_j2) ||
      __ODD (two_m2 + two_j2) ||
      __ODD (two_m3 + two_j3))
    return NAN;

  /* Check for positive j */
  if (two_j1 < 0 || two_j2 < 0 || two_j3 < 0)
    return NAN;

  /* Check sum of Ms is 0 */
  if (two_m1 + two_m2 + two_m3 != 0)
    return 0.0;

  /* And, finally check triangle condition is met */
  if (!is_triangle (two_j1, two_j2, two_j3))
    return 0.0;

  wigner3j_family_j (two_j2, two_j3, two_m2, two_m3,
                     buff, &two_jmin, &two_jmax);

  return buff[(two_j1 - two_jmin) / 2];
}
int
wigner3j_family_m (const int two_j1, const int two_j2, const int two_j3,
		   const int two_m1, double family[], int *two_mmin,
		   int *two_mmax)
{
  params_3j_m p;

  if (!is_triangle (two_j1, two_j2, two_j3))
    return __FAILURE;

  if (abs (two_m1) > two_j1)
    return __FAILURE;

  /* Check j1 and m1 are both integer or both half integer */
  if (__ODD (two_m1 + two_j1))
    return __FAILURE;

  *two_mmin = __MAX(-two_j2, -two_j3 - two_m1);
  *two_mmax = __MIN(two_j2, two_j3 - two_m1);

  p.two_j1 = two_j1;
  p.two_j2 = two_j2;
  p.two_j3 = two_j3;
  p.two_m1 = two_m1;

  p.j1 = two_j1 / 2.0;
  p.j2 = two_j2 / 2.0;
  p.j3 = two_j3 / 2.0;
  p.m1 = two_m1 / 2.0;

  p.two_mmin = *two_mmin;
  p.two_mmax = *two_mmax;

  LL98 (family, *two_mmin, *two_mmax, &p, X_3j_m, Y_3j_m, Z_3j_m,
	normalize_3j_m);

  return __SUCCESS;
}
Exemple #6
0
 void Element::calc_diameter()
 {
   double max, l;
   if (is_triangle())
   {
     max = 0.0;
     for (int i = 0; i < 3; i++)
     {
       int j = next_vert(i);
       l = sqr(vn[i]->x - vn[j]->x) + sqr(vn[i]->y - vn[j]->y);
       if (l > max)
         max = l;
     }
   }
   else
   {
     max = sqr(vn[0]->x - vn[2]->x) + sqr(vn[0]->y - vn[2]->y);
     l = sqr(vn[1]->x - vn[3]->x) + sqr(vn[1]->y - vn[3]->y);
     if (l > max)
       max = l;
   }
   this->diameter = sqrt(max);
 }
void
Scene_polyhedron_item::compute_normals_and_vertices(void) const
{
    positions_facets.resize(0);
    positions_lines.resize(0);
    positions_feature_lines.resize(0);
    normals_flat.resize(0);
    normals_gouraud.resize(0);

    //Facets
    typedef Polyhedron::Traits	    Kernel;
    typedef Kernel::Point_3	    Point;
    typedef Kernel::Vector_3	    Vector;
    typedef Polyhedron::Facet_iterator Facet_iterator;
    typedef Polyhedron::Halfedge_around_facet_circulator HF_circulator;

    Facet_iterator f = poly->facets_begin();
    for(f = poly->facets_begin();
        f != poly->facets_end();
        f++)
    {
      if (f == boost::graph_traits<Polyhedron>::null_face())
        continue;

      if(!is_triangle(f->halfedge(),*poly))
      {
          triangulate_facet(f);
      }
      else
      {
          int i=0;
          HF_circulator he = f->facet_begin();
          HF_circulator end = he;
          CGAL_For_all(he,end)
          {

                // If Flat shading:1 normal per polygon added once per vertex

                Vector n = CGAL::Polygon_mesh_processing::compute_face_normal(f, *poly);
                normals_flat.push_back(n.x());
                normals_flat.push_back(n.y());
                normals_flat.push_back(n.z());


                //// If Gouraud shading: 1 normal per vertex

                n = CGAL::Polygon_mesh_processing::compute_vertex_normal(he->vertex(), *poly);
                normals_gouraud.push_back(n.x());
                normals_gouraud.push_back(n.y());
                normals_gouraud.push_back(n.z());

                //position
                const Point& p = he->vertex()->point();
                positions_facets.push_back(p.x());
                positions_facets.push_back(p.y());
                positions_facets.push_back(p.z());
                positions_facets.push_back(1.0);
                i = (i+1) %3;
            }
        }
    }
void
Scene_polyhedron_item::compute_normals_and_vertices(void) const
{
    positions_facets.resize(0);
    positions_lines.resize(0);
    positions_feature_lines.resize(0);
    normals_flat.resize(0);
    normals_gouraud.resize(0);
    number_of_null_length_edges = 0;
    number_of_degenerated_faces = 0;
    //Facets
    typedef Polyhedron::Traits	    Kernel;
    typedef Kernel::Point_3	    Point;
    typedef Kernel::Vector_3	    Vector;
    typedef Polyhedron::Facet_iterator Facet_iterator;
    typedef Polyhedron::Halfedge_around_facet_circulator HF_circulator;
    self_intersect = CGAL::Polygon_mesh_processing::does_self_intersect(*poly);

    Facet_iterator f = poly->facets_begin();

    for(f = poly->facets_begin();
        f != poly->facets_end();
        f++)
    {

        if(!is_triangle(f->halfedge(),*poly))
        {
            is_triangulated = false;
            triangulate_facet(f);
        }
        else
        {
            int i=0;
            HF_circulator he = f->facet_begin();
            HF_circulator end = he;
            CGAL_For_all(he,end)
            {

                // If Flat shading:1 normal per polygon added once per vertex

                Vector n = CGAL::Polygon_mesh_processing::compute_face_normal(f, *poly);
                normals_flat.push_back(n.x());
                normals_flat.push_back(n.y());
                normals_flat.push_back(n.z());


                //// If Gouraud shading: 1 normal per vertex

                n = CGAL::Polygon_mesh_processing::compute_vertex_normal(he->vertex(), *poly);
                normals_gouraud.push_back(n.x());
                normals_gouraud.push_back(n.y());
                normals_gouraud.push_back(n.z());

                //position
                const Point& p = he->vertex()->point();
                positions_facets.push_back(p.x());
                positions_facets.push_back(p.y());
                positions_facets.push_back(p.z());
                positions_facets.push_back(1.0);
                i = (i+1) %3;
            }
            if(CGAL::Polygon_mesh_processing::is_degenerated(f,
                                                             *poly,
                                                             get(CGAL::vertex_point, *poly),
                                                             poly->traits()))
                number_of_degenerated_faces++;

        }
    }
Exemple #9
0
//
// Function:
//      can_follow_poker
// Description:
//      根据请求,检查要出的牌是否合法。如果合法,则将牌的属性保存在pp。(用于接牌)
// Parameter:
//      pp  - 用于保存扑克牌序列的属性
//      vec - 扑克牌的索引数组,其元素为指向POKER的索引,取值范围为0~53
//      num - 索引数组的长度
//      req - 请求出牌的属性
// Return:
//      操作成功返回true,否则返回false.
// Remark:
//      调用者需判断该函数的返回值,若返回false,表示无法判断牌的属性,该组牌
//      为不合法序列。
//      传入的参数 vec 为全局扑克牌的索引,而不是玩家当前牌的索引,否则,调用
//      该函数前需要进行转换。
//
POKER_API 
bool can_follow_poker(POKER_PROPERTY* pp, int vec[], int num, POKER_PROPERTY* req)
{
    int value;

    assert((pp != NULL) && (req != NULL));

    // 当前要出的牌是双王炸弹
    if (is_king_bomb(vec, num, &value)) {
        pp->type = BOMB;
        goto can_follow;
    }

    // 当前要出的牌是炸弹
    if (is_four_bomb(vec, num, &value)) {
        if ((req->type != BOMB) || ((req->type == BOMB) && (value > req->value))) {
            pp->type = BOMB;
            goto can_follow;
        } else {
            return false;
        }
    }

    // 当前要出的牌不是炸弹,但上家的牌是炸弹
    if (req->type == BOMB) {
        return false;
    }
    
    // 上家的牌不是炸弹,当前要打出的牌也不是炸弹
    if (num != req->num) {
        return false;
    }

    //
    // 到这里,说明上家出的牌与当前要出的牌都不是炸弹,并且数量相等,因此,
    // 只需要比较它们的类型和值即可。
    //
    switch (req->type) {
        case SINGLE:
            if (is_single(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case PAIR:
            if (is_pair(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case TRIANGLE:
            if (is_triangle(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case THREE_PLUS_ONE:
            if (is_three_plus_one(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case THREE_PLUS_TWO:
            if (is_three_plus_two(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case FOUR_PLUS_TWO:
            if (is_four_plus_two(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case FOUR_PLUS_FOUR:
            if (is_four_plus_four(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case SERIES:
            if (is_series(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case SERIES_PAIR:
            if (is_series_pair(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case SERIES_TRIANGLE:
            if (is_series_triangle(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case SERIES_THREE_PLUS_ONE:
            if (is_series_three_plus_one(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case SERIES_THREE_PLUS_TWO:
            if (is_series_three_plus_two(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case SERIES_FOUR:
            if (is_series_four(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case SERIES_FOUR_PLUS_TWO:
            if (is_series_four_plus_two(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        case SERIES_FOUR_PLUS_FOUR:
            if (is_series_four_plus_four(vec, num, &value)) {
                goto type_matched;
            } else {
                return false;
            }

        default:
            return false;
    }

type_matched:
    if (value <= req->value) {
        return false;
    }

    pp->type = req->type;

can_follow:
    pp->value = value;
    pp->num = num;

    return true;
}
Exemple #10
0
//
// Function:
//      get_poker_property
// Description:
//      获取出牌的相关属性
// Parameter:
//      pp  - [out] poker property if succeed
//      vec - poker vector to be analyzed. The element are indexes to GLOBAL poker.
//      num - poker num to be analyzed
// Return:
//      E_NONE if everything is OK, else the pokers are not valid.
// Remark:
//      the poker vector in array vec should be sorted in ascend.
//
POKER_RET get_poker_property(POKER_PROPERTY* pp, int vec[], int num)
{
    int value;

    assert(pp != NULL);

    if (is_single(vec, num, &value)) {
        pp->type = SINGLE;
        goto match_succeed;
    } else if (is_pair(vec, num, &value)) {
        pp->type = PAIR;
        goto match_succeed;
    } else if (is_king_bomb(vec, num, &value)) {
        pp->type = BOMB;
        goto match_succeed;
    } else if (is_triangle(vec, num, &value)) {
        pp->type = TRIANGLE;
        goto match_succeed;
    } else if (is_four_bomb(vec, num, &value)) {
        pp->type = BOMB;
        goto match_succeed;
    } else if (is_three_plus_one(vec, num, &value)) {
        pp->type = THREE_PLUS_ONE;
        goto match_succeed;
    } else if (is_three_plus_two(vec, num, &value)) {
        pp->type = THREE_PLUS_TWO;
        goto match_succeed;
    } else if (is_four_plus_two(vec, num, &value)) {
        pp->type = FOUR_PLUS_TWO;
        goto match_succeed;
    } else if (is_four_plus_four(vec, num, &value)) {
        pp->type = FOUR_PLUS_FOUR;
        goto match_succeed;
    } else if (is_series(vec, num, &value)) {
        pp->type = SERIES;
        goto match_succeed;
    } else if (is_series_pair(vec, num, &value)) {
        pp->type = SERIES_PAIR;
        goto match_succeed;
    } else if (is_series_triangle(vec, num, &value)) {
        pp->type = SERIES_TRIANGLE;
        goto match_succeed;
    } else if (is_series_three_plus_one(vec, num, &value)) {
        pp->type = SERIES_THREE_PLUS_ONE;
        goto match_succeed;
    } else if (is_series_three_plus_two(vec, num, &value)) {
        pp->type = SERIES_THREE_PLUS_TWO;
        goto match_succeed;
    } else if (is_series_four(vec, num, &value)) {
        pp->type = SERIES_FOUR;
        goto match_succeed;
    } else if (is_series_four_plus_two(vec, num, &value)) {
        pp->type = SERIES_FOUR_PLUS_TWO;
        goto match_succeed;
    } else if (is_series_four_plus_four(vec, num, &value)) {
        pp->type = SERIES_FOUR_PLUS_FOUR;
        goto match_succeed;
    } else {
        return E_INVALID;
    }

match_succeed:
    pp->value = value;
    pp->num = num;

    return E_NONE;
}