Article From:


There is a big rectangle and two small rectangles. First we put the two small rectangles in the big rectangle and ask whether the small rectangles will overlap.

Analysis: enumerate all cases. The two small rectangles are placed in the upper left corner and the lower right corner of the large rectangle respectively. Let’s see if their width is longer than the length and width of the rectangle. Let’s see if the length and width of the two combinations are longer than that of the big rectangle.

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 using namespace std;
 6 int x,y;
 8 bool judge(int x1,int y1,int x2,int y2)
 9 {
10     int x3,y3;
11     x3=x1+x2;
12     y3=y1+y2;
13     if ( x1>x || x2>x || y1>y || y2>y ) return false;
14     if ( x3>x && y3>y ) return false;
15     return true;
16 }
18 int main()
19 {
20     int x1,y1,x2,y2,ans;
21     bool flag;
22     while ( scanf("%d%d%d%d%d%d",&x,&y,&x1,&y1,&x2,&y2)!=EOF )
23     {
24         flag=false;
25         if ( judge(x1,y1,x2,y2) ) flag=true;
26         if ( judge(y1,x1,x2,y2) ) flag=true;
27         if ( judge(x1,y1,y2,x2) ) flag=true;
28         if ( judge(y1,x1,y2,x2) ) flag=true;
29         if ( flag ) printf("YES\n");
30         else printf("NO\n");
31     }
32     return 0;
33 }




There is a hexagon with equal angles. Each side is known. First, how many hexagonal equilateral triangles can be divided into 1 sides?

Analysis: the last number = the area of the hexagon’s area equal to 1 of the equilateral triangle, so only the area of the hexagon can be asked. Direct segmentation is more difficult to operate, so consider adding hexagon to a large equilateral triangle and subtract three small equilateral triangles. It is specific to take arbitrary continuousThe three side (I take the first three a[0], a[1], a[2]), and expand it into a straight line, and the final triangle is an equilateral triangle with the bottom of the a[0]+a[1]+a[2]. Subtracting equilateral triangles that are a[0], a[2] and a[4] respectively.

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 using namespace std;
 6 const int maxn=6;
 7 int a[maxn];
 9 int main()
10 {
11     int ans,sum,i,j,k,A;
12     for ( i=0;i<maxn;i++ ) scanf("%d",&a[i]);
13     A=a[0]+a[1]+a[2];
14     ans=(A*A-a[0]*a[0]-a[2]*a[2]-a[4]*a[4]);
15     printf("%d\n",ans);
16     return 0;
17 } 




Given two strings, let you determine whether the two strings are equal or not. The same conditions are as follows:1.Two strings are equal2.The string a is divided into strings of equal growth A1, a2.String B divides the string B1 with equal growth, b2.When a1=b1, a2=b2 or a1=b2, a2=b1 is equal

Analysis: simulation problem. It can be simulated as required by the title, but a small transformation can be made, and the comparison of the two strings is converted to “sort” each string itself according to the dictionary order size, and compare the two strings at the end of the same size.

To divide a string into two parts, we need to use the substr function in the string library, string a=s.substr (0, len/2), 0 to indicate the starting position, and len/2 to represent the length.

using namespace std;
string split(string a)
    int len=a.size();
    if ( len%2==1 ) return a;
    string a1=a.substr(0,len/2),a2=a.substr(len/2,len/2);
    string b1=split(a1),b2=split(a2);
    return b1>b2?b2+b1:b1+b2;

int main()
    string a,b;
    if ( a==b ) printf("YES\n");
    else printf("NO\n");
    return 0;



Link of this Article: Codeforces Round #313 (Div. 2)

Leave a Reply

Your email address will not be published. Required fields are marked *