zoukankan      html  css  js  c++  java
  • 7月23号的题目:Cutting a Painted Polygon&&Function Run Fun&&Sumdiv&&Raid&&A simple stone game

                                                                     Cutting a Painted Polygon

     Cutting a Painted Polygon
    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

    Description

    There is a convex polygon with vertices painted in three colors: Red (R), Green (G) and Blue (B). It is known that all the colors are present and any two neighbor vertices have different colors. You are to find out whether it is possible to cut this polygon with noncrossing diagonals so that each of the obtained triangles would have all vertices of different colors: one red, one green and one blue vertex. Point out a possible way of the cutting if the cutting is possible.

    Input

    The first line contains a number N of the polygon vertices (4 ≤ N ≤ 1000). There are N symbols of the set {'R', 'G', 'B'} in the second line that specify a color for the correspondent vertex.

    Output

    The first line should contain either a number of drawn diagonals in case the required cutting is possible or the number 0 otherwise (cutting is impossible). In the first case the following lines should contain a description of the drawn diagonals. The description of a diagonal takes one line and consists of diagonal vertices numbers. The numbers are separated with a space. If there are several possible cuttings that satisfy the requirements you may output any of them.

    Sample Input

    inputoutput
    7
    RBGBRGB
    
    4
    1 3
    3 7
    5 7
    5 3
    

    题目意思就是找线(把凸多边形分成多个三角形且顶点颜色各不相同

    仔细观察可知道题目没有不可能的情况(输出不会为0)。本人的一直纠结的:从相邻三点进行比较,特别注意要保证把中间的点切除后,剩余的凸多边形一定要保证有三种不同的颜色!!!不然就换种切法。

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<string>
     4 #include<string.h>
     5 using namespace std;
     6 int main()
     7 {
     8     int j,t,i,w,r,g,h,as1,as2,as;
     9     char b[1000],a[10005];
    10     int c[6000];
    11     while(scanf("%d",&t)!=EOF)
    12     {
    13         r=0;g=0;h=0;w=0;j=1;
    14         scanf("%s",&a);
    15     for(i = 0; i < t; i++)
    16         {
    17             if(a[i] == 'R') r++;//统计数量
    18             else if(a[i] == 'G') g++;//统计数量
    19             else if(a[i] == 'B') h++;//统计数量
    20         }
    21     printf("%d
    ",t-3);
    22     for(;;)
    23     {
    24         for(i=0;i<t;i++)
    25         {
    26 
    27             if(a[i]!='0')
    28             {
    29                 b[j]=a[i];
    30                 c[j]=i+1;
    31                 j++;
    32                 if(j==4)
    33                 {
    34                     if((b[2]=='R'&&r>1)||(b[2]=='G'&&g>1)||(b[2]=='B'&&h>1))//判断是不是能保证还有三种不同的颜色
    35                     {
    36                         if(b[1]!=b[2]&&b[2]!=b[3]&&b[3]!=b[1])
    37                     {
    38                         if(w!=t-3)
    39                         {printf("%d %d
    ",c[1],c[3]);w++;}
    40                         if(b[2]=='R')
    41                             r--;
    42                         if(b[2]=='G')
    43                             g--;
    44                         if(b[2]=='B')
    45                             h--;
    46                         if(w==t-3)
    47                             break;
    48                         a[c[2]-1]='0';
    49                         i=c[3]-2;
    50                     }
    51                     else
    52                     {
    53                         i=c[2]-2;
    54                     }
    55                     j=1;
    56                     }
    57                     else
    58                     {
    59                         i=c[2]-2;//不然的话,把中间的点作为起点再进行切与比较
    60                         j=1;
    61                     }
    62                 }
    63             }
    64         }
    65     if(w==t-3)
    66         break;
    67     }
    68     }
    69     return 0;
    70 }

                                                                     Function Run Funhttp://poj.org/problem?id=1579

    水题,但没做出来,主要没领悟计算机语言的精髓:用递归啊!!

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<algorithm>
     4 using namespace std;
     5 int a[210][210][201];
     6 int w(int i,int j,int k)
     7 {
     8     if(i<=0||j<=0||k<=0)
     9         return 1;
    10     else return a[i][j][k];
    11 }
    12 int main()
    13 {
    14     int i,j,k,a1,b,c;
    15 for(i=1;i<=20;i++)
    16 for(j=1;j<=20;j++)
    17 for(k=1;k<=20;k++)
    18 {
    19     if(i<j&&j<k)
    20         a[i][j][k]=w(i,j,k-1)+w(i,j-1,k-1)-w(i,j-1,k);
    21     else
    22         a[i][j][k]=w(i-1,j,k)+w(i-1,j-1,k)+w(i-1,j,k-1)-w(i-1,j-1,k-1);
    23 }
    24 while(scanf("%d%d%d",&a1,&b,&c)!=EOF)
    25 {
    26     if(a1==-1&&b==-1&&c==-1)
    27         break;
    28     if(a1<=0||b<=0||c<=0)
    29         printf("w(%d, %d, %d) = 1
    ",a1,b,c);
    30     else if(a1>20||b>20||c>20)
    31         printf("w(%d, %d, %d) = 1048576
    ",a1,b,c);
    32     else
    33         printf("w(%d, %d, %d) = %d
    ",a1,b,c,a[a1][b][c]);
    34 }
    35     return 0;
    36 }

                                                                                Sumdiv

    直接进入http://www.cnblogs.com/lyy289065406/archive/2011/07/31/2122790.html

    思路全都有的。。。

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<algorithm>
     4 using namespace std;
     5 int MOD=9901;
     6 __int64 pow(__int64 p,__int64 n)
     7 {
     8     __int64 sq=1;
     9     while(n>0)
    10     {
    11         if(n%2)
    12             sq=(sq*p)%MOD;
    13             n=n/2;
    14             p=p*p%MOD;
    15     }
    16     return sq;
    17 }
    18 __int64 sum(__int64 p,__int64 n)
    19 {
    20     if(n==0)
    21         return 1;
    22     if(n%2)
    23     return (sum(p,n/2)*(1+pow(p,n/2+1)))%MOD;
    24     else
    25         return (sum(p,n/2-1)*(1+pow(p,n/2+1))+pow(p,n/2))%MOD;
    26 }
    27 int main()
    28 {
    29     __int64 a,b;
    30     int p[10002],n[100003];
    31     int i,k=0;
    32     scanf("%I64d %I64d",&a,&b);
    33     for(i=2;i*i<=a;)
    34     {
    35         if(a%i==0)
    36         {
    37             p[k]=i;
    38             n[k]=0;
    39             while(a%i==0)
    40             {
    41                 n[k]++;
    42                 a=a/i;
    43             }
    44             k++;
    45         }
    46         if(i==2)
    47             i++;
    48         else
    49             i=i+2;
    50     }
    51     if(a!=1)
    52     {
    53         p[k]=a;
    54         n[k++]=1;
    55     }
    56     int ans=1;
    57     for(i=0;i<k;i++)
    58         ans=(ans*(sum(p[i],n[i]*b)%MOD))%MOD;
    59     cout<<ans<<endl;
    60     return 0;
    61 }

                                                           Raidhttp://poj.org/problem?id=3714

    题目大意是:两个坐标集,求两个坐标集之间最短的点距。

    因为看起来,但往往这种问题都会超时!!(这就需要进行剪枝的!)

    小技巧:把这俩坐标集放在同一个子集中!

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<math.h>
     4 #include<algorithm>
     5 using namespace std;
     6 struct A
     7 {
     8     double x;
     9     double y;
    10     int bia0;
    11 }p[20000000];//值过大,就用double与__int64。不然就用大数了吧。。。。(自己的推测)
    12 bool comp1(A x,A y)
    13 {
    14     if(x.x<y.x)
    15         return true;
    16     else if(x.x==y.x)
    17     {
    18         if(x.y<y.y)
    19             return true;
    20     }
    21     return false;
    22 }
    23 int main()
    24 {
    25     double MIN,d;
    26     int t,i,j,n;
    27     scanf("%d",&t);
    28     while(t--)
    29     {
    30         MIN=50000000;
    31         scanf("%d",&n);
    32         for(i=0;i<n;i++)
    33         {
    34             scanf("%lf %lf",&p[i].x,&p[i].y);
    35             p[i].bia0=1;
    36         }
    37         for(i=n;i<n*2;i++)
    38         {
    39             scanf("%lf %lf",&p[i].x,&p[i].y);
    40             p[i].bia0=0;
    41         }
    42         sort(p,p+n*2,comp1);
    43         for(i=0;i<n*2-1;i++)
    44             for(j=i+1;j<n*2;j++)
    45         {
    46             if(p[i].bia0==p[j].bia0)//剪枝
    47                continue;
    48             if(p[j].x-p[i].x>=MIN)//剪枝
    49                 break;
    50             d=sqrt((p[j].x-p[i].x)*(p[j].x-p[i].x)+(p[j].y-p[i].y)*(p[j].y-p[i].y));
    51             if(d<MIN)
    52                 MIN=d;
    53         }
    54         printf("%.3lf
    ",MIN);
    55     }
    56     return 0;
    57 }
  • 相关阅读:
    关于C语言中的绝对值函数
    B. Interesting drink(水题 二分)
    A. Boring Apartments(水题)
    A. FashionabLee(水题)
    A. Collecting Coins(水题)
    A. Fancy Fence(水题)
    最小公因数,最小公倍数,以及快速幂模板
    android:layout_gravity 和 android:gravity 的区别
    Android开发之Intent略解
    java中类的创建及初始化过程
  • 原文地址:https://www.cnblogs.com/tt123/p/3222417.html
Copyright © 2011-2022 走看看