学习心得(code)

superlong@CoreCoder

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  74 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks

公告

文字可能放在http://blog.csdn.net/superlong100,此处存放代码

常用链接

留言簿(4)

我参与的团队

搜索

  •  

最新随笔

最新评论

  • 1. re: Poj 1279
  • 对于一个凹多边形用叉积计算面积 后能根据结果的正负来判断给的点集的时针方向?
  • --bsshanghai
  • 2. re: Poj 3691
  • 你写的这个get_fail() 好像并是真正的get_fail,也是说fail指向的串并不是当前结点的子串。为什么要这样弄呢?
  • --acmer1183
  • 3. re: HDU2295[未登录]
  • 这个是IDA* 也就是迭代加深@ylfdrib
  • --superlong
  • 4. re: HDU2295
  • 评论内容较长,点击标题查看
  • --ylfdrib
  • 5. re: HOJ 11482
  • 呵呵..把代码发在这里很不错..以后我也试试...百度的编辑器太烂了....
  • --csuft1

阅读排行榜

评论排行榜

#include <stdio.h>
#include 
<math.h>

struct point
{
    
double x, y;
};

int n;
point p[
95], up[95], down[95];
int   l_up, l_down;
double area_up, area_down, upx, downx;

inline 
double area(point *po, int len)
{
    
double sum = 0;
    
for(int i = 0; i < len; i ++)
        sum 
+= po[i].x * po[i + 1].y - po[i].y * po[i + 1].x;
    
return sum / 2;
}

inline 
double centroid(point *po, int len)
{
    
double sum = 0;
    
for(int i = 0; i < len; i ++)
        sum 
+= (po[i].x + po[i + 1].x) * (po[i].x * po[i + 1].y - po[i].y * po[i + 1].x);
    
return sum;
}

int main()
{
    
double x1, x2, y1, y2, x;
    
while(scanf("%d"&n) != EOF)
    {
        
int i;
        
for(i = 0; i < n; i ++)
            scanf(
"%lf %lf"&p[i].x, &p[i].y);
        p[n] 
= p[0];
        l_up 
= 0;
        l_down 
= 0;
        
for(i = 0; i < n; i ++)
        {
            
if(p[i].y >= 0)    up[l_up++= p[i];
            
if(p[i].y <= 0)    down[l_down++= p[i];
            
if(p[i].y * p[i + 1].y < 0)
            {
                x1 
= p[i].x;
                x2 
= p[i + 1].x;
                y1 
= p[i].y;
                y2 
= p[i + 1].y;
                x 
= x1 + (x2 - x1) * y1 / (y1 - y2);
                point tp;
                tp.x 
= x; tp.y = 0;
                up[l_up
++= tp;
                down[l_down
++= tp;
            }
        }
        up[l_up] 
= up[0];
        down[l_down] 
= down[0];
        
        area_up 
= area(up, l_up);
        area_down 
= area(down, l_down);
        upx 
= centroid(up, l_up);
        downx 
= centroid(down, l_down);
        
double cx_up = upx/(6 * area_up), cx_down = downx/(6 * area_down);
        
if( fabs(cx_up - cx_down) < 1e-8)
            puts(
"Balanced.");
        
else if(cx_up > cx_down)
            printf(
"CE is forward of CLR by %.2lf units.\n",cx_up - cx_down);
        
else
            printf(
"CE is aft of CLR by %.2lf units.\n",cx_down - cx_up);    
    }
}

posted on 2009-08-29 16:28 superlong 阅读(133) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理