#个人赛第七场解题总结 # (Fzu 18,883 angle Problem II && Fzu 1886 music)

Source: Internet
Author: User

A-Triangle Problem II (computational geometry)
Time Limit:MS Memory Limit:32768KB 64bit IO Format:%i64d &A mp %i64u SubmitStatusPracticeFzu 1888

Description

The coordinates of n points on a given plane, now your task is to count the area and values of the triangles that make up any 3 points.

Input

There are multiple sets of data

The first line of data contains a positive integer t that represents the number of data groups (1 <= T <= 100) next to the T-group data.

For each set of data,

The first line contains a positive integer n, which represents the number of points on the plane. (1<= N <= 50,)

Next n rows, each row contains 2 real numbers Xi, Yi, representing the coordinates of the point I (0.00 <= xi,yi <= 100.00 decimal point up to 2 bits)

Data does not guarantee that points with the same coordinates will not appear.

Output

For each set of data, first output "case D:", D is the data number (starting from 1). Only one real number is output, representing the area and the value. (1 digits after the output point)

Sample Input

130 01 11 0

Sample Output

Case 1:0.5

Hint

Use a double instead of float to avoid accuracy problems.
Thinking "cross product calculation, pay attention to accuracy
Code:
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < Math.h>using namespace Std;const double Pi=acos ( -1.0); const double Eps=1e-6;const int maxn=105;struct node{    Double x, y;}  Point [MAXN];d ouble Cross (node A1,node a2,node a3) {    double aa= (A2.Y-A1.Y) * (a3.x-a1.x)-(a2.x-a1.x) * (A3.Y- A1.Y);    return Fabs (aa/2.0);} int main () {    int t,n,m,tot=1;    cin>>t;    while (t--)    {        cin>>n;        for (int i=0; i<n; i++)        {            cin>>point[i].x>>point[i].y;        }        Double sum=0;        for (int i=0; i<n; i++)            for (int j=i+1; j<n; j + +)                for (int k=j+1; k<n; k++)                    Sum+=cross (Point[i], Point[j],point[k]);        printf ("Case%d:%.1lf\n", tot++,sum);    }    return 0;}

B-Music (Fzu 1886 music 201,100-degree star in the preliminary round a title adaptation)
Time limit:1000ms Memory limit:32768kb 64bit IO format:%i64d &%i64u
Submitstatuspracticefzu 1886
Description
Chjing computer has a lot of songs, each song by a singer, Fish Leong, JJ Lin, Jay Chou Ah, more. Every time I listen to a song, chjing always follow the order of the playlist and listen to it sequentially. So I often hear a singer sing a song in succession. It's not good to hear the same person's song, so Chjing decided to calculate the fun value of all the songs on the list and choose the playlist with the greatest fun value.
The fun value of a song is calculated, assuming this song is in position I, sung by the singer T, then in the position greater than I and nearest to I J find a song, also t sing, this song's Fun value is (j-i). If you can't find it, this song has a fun value of 0. A fun value for a playlist is a fun value that is added to the song at all locations.
Input
The first line is an integer t, which indicates that there is a T test case.
After each use case an integer n, which indicates that there are n songs. (0 < n <= 22)
Then n integers, the value of the I integer is S, and the song of the first I is sung by S. For the sake of convenience, S is a number representing a singer. 0 <= S <= 15.
Output
print "Case h:", H is the H use cases.
Then the next line, output the desired fun value.
A blank line is output after each sample.
Sample Input
231 1 261 2 2 2 3 3
Sample Output
Case 1:2case 2:8
Hint
First example: sort order 1 2 1Fun value: 2+0+0=2; second sample: Sort order: 3 2 1 2 3 2Fun value: 4+2+0+2+0+0=8
"Problem-solving ideas":
Idea one: N song, t a singer, if every singer has only one elder brother, there is no fun value, otherwise the number of songs more than one song, or at least two elder brother, then the answer is: Suppose N song, there is a T singer at least two songs, the rest
N-t Song is only one song, statistics T on the first and last difference can be
A different idea:
Thought two: Greedy thoughts such as 1 1 2 2 3 must be put two left one right of 12231 and then continue to change the same way 12321 this change will be the best
The first change inserted 3 numbers moved 4 units added 4 goodwill degrees
The second change inserted 1 numbers moved 2 units added 2 goodwill degrees
Actually all the same, ~ ~.
Idea a code:
#include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <stack > #include <algorithm>using namespace std;const int Maxn=100;const double Pi=acos ( -1.0); #define  LL  __ Int64int a[maxn],b[maxn];bool Flag[100001];int Main () {    int t,n,tt,i,j,tot=1;    cin>>t;    while (t--)    {        memset (b,0,sizeof (b));        cin>>n;        for (i=0; i<n; i++) {            cin>>j;            b[j]++;        }        tt=0;        for (i=0; i<maxn; i++) {            if (b[i]!=0)            {                a[tt++]=b[i];            }        }        int ss=0;        for (i=0; i<tt; i++) {            if (a[i]>1)            {                ss+=n-1;                n=n-2;            }        }        printf ("Case%d:\n", tot++);        printf ("%d\n\n", ss);    }    return 0;}
Idea two:
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < Math.h>using namespace Std;const double Pi=acos ( -1.0); const double Eps=1e-6;const int Maxn=105;int A[maxn];bool flag[ Maxn];int Main () {    int t,n,m,res,tot=1;    scanf ("%d", &t);    while (t--)    {        scanf ("%d", &n);        memset (flag,false,sizeof (flag));        for (int i=0; i<n; i++)  scanf ("%d", &a[i]);        Sort (a,a+n);        m=n+1,res=0;        for (int i=0; i<n-1; i++)        {            if ((Flag[a[i]]==false) &&a[i]==a[i+1])            {                m-=2;                res+=m;                flag[a[i]]=true;            }        }        printf ("Case%d:\n", tot++);        printf ("%d\n\n", res);    }    return 0;}





#个人赛第七场解题总结 # (Fzu 18,883 angular question II && Fzu 1886 music)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.