UCF Local Programming Contest 2013(Practice)解(补)题报告

前言

刚开始光速解决前三道,看到D是模拟,就去看I,这一看不打紧,整整卡了四个小时。在朋友的提醒下才做了出来。有一说一,这真的是脚造的数据,double过不了只有float能过?我被整吐了。H题卡到最后都没过,原因竟然是angle/PI*180能过但是angle/180*PI过不了,我寻思着应该后者的误差小一些,搞的也没看中间那几道,刚刚看了都是模拟,算了不想补了

A - The Suffix Game(简单字符串)

题目链接

Dr. Orooji’s twins, Mack and Zack, have discovered a new game to help them pass the time.First, Mack will select a word from the dictionary and write it down. Next, Zack selects a word and writes it down below Mack’s word, taking care that the ends of the words are aligned.For instance, if Mack chooses the word “random”, and Zack chooses “kingdom”, then they will write them down as:Observe that the shorter word has been padded with a space at the front, to make the ends of the words line up.Next, they will take turns examining the last letter of each word. If bothstrings end with the same letter, it will be removed from the ends of both strings. This procedure continues until the final characters do not match. So, for the previous example, the procedure will give:There is a catch, though. When the game ends, the two resulting words are written down in a special notebook. Since the twins insist on writing exactly two words, neither word must be completely consumed. Thus, the shortening procedure will end if either of the strings is shrunk down to a single character (see Sample Input/Output for clarification).
The Problem:
Dr.Orooji has decided to beat the twins at their own game, literally. Your job is to assist him by writing a program that, given the two starting words of a game, will play the game to the end and output the two final words.

The Input:
Mack and Zack play multiple games. The first of the input to your program will be an interger gg. indicating the number of games to be played. This will be followed by gg lines, with two words on each line, indicating the two initial words. The words will consist of only lowercase letters(‘a’ - ‘z’), each word at least one letter and at most 20 letters, first word starting in column one and the second word separated from the first word by exactly one space.

The Output:
At the beginning of the each test case, output “Game #g:”, where gg is the game number (staring from 1). Then, output the two input words (indented three columns). Finally, output the results of the game (indented three columns) by saying: “The words entered in the notebook are w1 and w2.”, where w1w1 and w2w2 represent the two final words, in the same order as the originals.Leave a blank line after the output for each test case. Follow the format illustrated in Sample Output.

1.题意:去掉两个字符串相同的后缀,且每个字符串至少剩一个字符

2.统计分别在什么位置二者不相等,如果有一个检测到-1,那么代表它是另一个串的后缀,直接取一个字符,另外一个串也多取一个字符。否则直接取当前检测的位置即可。我写的substr(),左闭右开,因此都得再加一

#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s1,s2,str1,str2;
    int n;
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n;
    for(int kase=1;kase<=n;kase++){
        cin>>s1>>s2;
        int x=s1.size()-1,y=s2.size()-1;
        while(s1[x]==s2[y] && x>=0 &&y>=0){
            x--;y--;
        }
        //cout<<x<<y<<endl;
        if(x<0 || y<0){
            x+=2,y+=2;
            str1=s1.substr(0,x);
            str2=s2.substr(0,y);
        }else{
            ++x,++y;
            str1=s1.substr(0,x);
            str2=s2.substr(0,y);
        }
        cout<<"Game #"<<kase<<":\n";
        cout<<"   The input words are "<<s1<<" and "<<s2<<".\n";
        cout<<"   The words entered in the notebook are "<<str1<<" and "<<str2<<".\n\n";
    }
    return 0;
}

B - Counting Triangles(简单三角形性质)

题目链接

Triangle Tom is at it again. This time, however, instead of attempting to calculate areas of triangles, he just wants to count how many of them there are. Given a list of possible points, your job will be to help Tom figure out how many different triangles can be formed with those points.
The Problem:
Given a list of points in the Cartesian plane, determine how many triangles (with all angles strictly less than 180°) can be formed with those points.

The Input:
The first line of the file will contain a single positive integer n(1 \le n \le 50)n(1≤n≤50), denoting the number of test cases in the file. The first line of each test case contains one integer,k(1 \le k \le 100)k(1≤k≤100), denoting the number of points for that test case. The second line of each test case contains kk ordered pairs of integers (separated by spaces) denoting the x and y coordinates of each point, respectively. It is guaranteed that -100 \le x \le 100−100≤x≤100 and -100 \le y \le 100−100≤y≤100 for all coordinates. It is also guaranteed that each point given will be unique.

The Output:
At the beginning of each test case, output "Test case #t: " where tt is the test case number (starting from 1). Follow this with a statement of the following form:x triangle(s) can be formed.where xx represents the distinct number of triangles that can be formed with the given points.Leave a blank line after the output for each data set. Follow the format illustrated in Sample Output.

1.题目大意:给出若干个点,判断这些点构成的三角形的个数

2.直接利用三角形两边之和大于第三边即可,注意开三重循环不要统计相同的点

#include <iostream>
#include <math.h>
using namespace std;
#define Vector Point
const double eps=1e-8;
const double PI=acos(-1.0);

int dcmp(double d){
    if(fabs(d)<eps) return 0;
    if(d<0) return -1;
    return 1;
}

struct Point{
    double x,y;
    Point(double a=0,double b=0){
        x=a,y=b;
    }
    Point operator + (Point p){ return Point(x+p.x,y+p.y); }
    Point operator - (Point p){ return Point(x-p.x,y-p.y); }
    Point operator * (double d){ return Point(x*d,y*d); }
    double operator * (Point p){ return x*p.x+y*p.y; }
    Point operator / (double d){ return Point(x/d,y/d); }
    double operator ^ (Point p){ return x*p.y-y*p.x; }
};

double dis(Point p){
    return sqrt(p*p);
}

bool isTangle(Point a,Point b,Point c){
    double d1=dis(a-b),d2=dis(a-c),d3=dis(b-c);
    if(dcmp(d1+d2-d3)>0 && dcmp(d2+d3-d1)>0 && dcmp(d1+d3-d2)>0) return true;
    return false;
}

Point P[1005];

int main()
{
    int t,n;
    //double a,b;
    scanf("%d",&t);
    for(int kase=1;kase<=t;kase++){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%lf%lf",&P[i].x,&P[i].y);
        }
        int ans=0;
        for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        for(int k=j+1;k<=n;k++){
            if(isTangle(P[i],P[j],P[k])) ans++;
        }
        printf("Test case #%d: %d triangle(s) can be formed.\n\n",kase,ans);
    }

    return 0;
}

C - UCF Hold-em Poker(简单模拟)

题目链接

直接模拟即可,没有难度

#include <iostream>
#include <string>
#include <set>
#include <map>
using namespace std;
map<char,int> mp;
set<char> st;

int judge(string s){
    st.clear();
    mp.clear();
    for(int i=0;i<s.size();i++){
        st.insert(s[i]);
        mp[s[i]]++;
    }
    int p4=0,p3=0,p2=0;
    for(auto i:st){
        if(mp[i]==4) p4++;
        if(mp[i]==3) p3++;
        if(mp[i]==2) p2++;
    }
    if(p4!=0) return 1;
    if(p3!=0 && p2!=0) return 2;
    if(p3!=0) return 3;
    if(p2!=0) return 4;
    return 5;
}

int main()
{
    int n;
    string s;
    scanf("%d",&n);
    for(int kase=1;kase<=n;kase++){
        cin>>s;
        int x=judge(s);
        printf("UCF Hold-em #%d: ",kase);
        cout<<s<<"\n";
        if(x==1) printf("Best possible hand: FOUR OF A KIND\n\n");
        else if(x==2) printf("Best possible hand: FULL HOUSE\n\n");
        else if(x==3) printf("Best possible hand: THREE OF A KIND\n\n");
        else if(x==4) printf("Best possible hand: TWO OF A KIND\n\n");
        else printf("Best possible hand: BUST\n\n");
    }
    return 0;
}

E - Gas Price Is Going Up/Down(字符串模拟)

题目链接

The gas stations have billboards showing the gas prices (we’ll assume only three categories of gas: Regular, Plus, and Super). These billboards display the prices of gas, but the problem is that sometimes some digits are missing from the prices on the billboards!
The Problem:
Given prices for the three categories of gas with at most one digit missing from a given price, you are to determine the exact value of each price. We will assume that Regular is cheaper than Plus which is cheaper than Super. Also assume that Regular is at least $2.00 and Super is at most $5.00.

The Input:
There will be multiple billboards (test cases) in the input file. The first input line contains a positive integer nn, indicating the number of billboards to be processed. The billboards will be on the following nn input lines, each on a separate line. Each billboard contains three prices, the first showing Regular, the second representing Plus, and the last showing Super. The first price starts in column one, each price uses three columns (decimal points are not in the input), and there is exactly one space separating prices. The characters used in a price are only digits 0 through 9 and hyphen to indicate missing digit (there is at most one hyphen per price). Since gas is at least $2.00, the digits 0 or 1 will not appear as the first character for a price in the input. Similarly, the maximum gas price ($5.00) dictates possible valid values for the first character.

The Output:
At the beginning of each test case, output “Gas Station #g:” where gg is the test case number (starting from 1). For each gas station, print the input values and then the output values (each on a separate line and indented three columns). If there are multiple possible (valid) answers, use the lowest valid value for Regular. Then, with the lowest valid value for Regular, use the lowest valid value for Plus. Then, with the lowest valid value for Plus, use the lowest valid value for Super. Assume that input values will always result into at least one possible valid answer.Leave a blank line after the output for each test case. Follow the format illustrated in Sample Output. Be sure to line up the output with spaces exactly as given in the Sample Output.

1.题意很简单,不再赘述

2.明显第一个串满足大于200后如果有’-'直接补0,再分情况讨论第二个串,再由第二个确定的串分情况讨论第三个串。放个标程算了自己写了一半不想写了

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>

using namespace std;

char R[4],P[4],S[4],RR[4],PP[4],SS[4];
int main(void)
{
    int T;
    scanf("%d",&T);
    int k=0;
    while(T--)
    {
        memset(R,0,sizeof R);
        memset(P,0,sizeof P);
        memset(S,0,sizeof S);
        scanf("%s%s%s",R,P,S);
        strcpy(RR,R);
        strcpy(PP,P);
        strcpy(SS,S);
        char *p;
        int sum1,sum2,sum3;
        p=NULL;
        p=strchr(R,'-');
        if(p)
        {
            for(int i=0; i<10; i++)
            {


                R[p-R]=i+'0';
                sum1=(R[0]-'0')*100+(R[1]-'0')*10+(R[2]-'0');
                if(sum1>=200)break;

            }
        }
        else{sum1=(R[0]-'0')*100+(R[1]-'0')*10+(R[2]-'0');}
        p=NULL;
        p=strchr(P,'-');
        if(p)
        {
            for(int i=0; i<10; i++)
            {
                P[p-P]=i+'0';
                sum2=(P[0]-'0')*100+(P[1]-'0')*10+(P[2]-'0');
                if(sum2>sum1)break;
            }
        }
        else{ sum2=(P[0]-'0')*100+(P[1]-'0')*10+(P[2]-'0');}
        p=NULL;
        p=strchr(S,'-');
        if(p)
        {
            for(int i=0; i<10; i++)
            {

                S[p-S]=i+'0';
                sum3=(S[0]-'0')*100+(S[1]-'0')*10+(S[2]-'0');
                if(sum3>sum2&&sum3<=500)break;
            }
        }
        else{sum3=(S[0]-'0')*100+(S[1]-'0')*10+(S[2]-'0');}
        printf("Gas Station #%d:\n",++k);
        printf("   Input:  %s %s %s\n",RR,PP,SS);
        printf("   Output: %s %s %s\n",R,P,S);
        printf("\n");
    }
    return 0;
}

H - In the Spotlight(简单计算几何)

题目链接

Starlet Stacie always insists that the spotlights must shine upon her sufficiently, regardless of where she stands on the stage. Otherwise, she makes a scene.Consider the floor of the stage to be a Cartesian plane, the front of the stage is the xx-axis and the sides of the stage are at x = 0x=0 and x = The spotlights are all mounted along the xx-axis, and are all aimed onto the stage (parallel to the yy-axis), though they might have different focus angles. Height above the stage floor isn’t important, so we need to consider only the 2-dimensional plane.The focus angle of each spotlight is an angle relative to the aimed direction, on either side, and indicates the area covered by that light beam. Thus each spotlight will essentially cover a stage area that is an isosceles triangle (with the back of the stage as the
Anything outside a spotlight’s triangular coverage area gets negligible illumination. The intensity of a light within the triangle (any point within .01 degrees of the focus angle is considered inside the triangle) is given by is the intensity of the light at its source point, and dd is the distance from the source point.If Stacie is standing within the coverage area of more than one light, the total intensity of light shining on her is simply the sum of all such lights.
The Problem:
Given Stacie’s stage position and the positions and intensities of various spotlights during a scene, find the intensity of light shining on Stacie.

The Input:
The first line of input will contain only a positive integer pp, which is the number of scenes to evaluate. This will be followed by pp scene descriptions. The first line of each scene description will contain three integers, representing Stacie’s position, and n(0 < n < 100)n(0<n<100), the number of lights that are turned on. The second line will contain nn distinct non-negative integers less than 1000: \alpha_1, \alpha_2, …\ \alpha_n1000:α ; these are the positions of the lights along the xx-axis. (Note that distance units are not provided because all distance units are the same.) The third line will contain nn positive integers less than 90: a_1, a_2, …\ a_n90:a these are the focus angles, in degrees, for each corresponding light on the preceding line. The fourth line of each scene description contains nn positive integers less than these are the intensities of the lights at their source points for each corresponding light on the preceding lines. All numbers on the same line will be separated from each other by exactly one space, with no leading or trailing spaces. (Use 3.14159265 for the value of π.)

The Output:
For each scene description, output a message of the form
Scene #s: Spotlight intensity on Stacie is t
where ss is the number of the scene in the input (counting from 1) and tt is the total light intensity, rounded to the nearest three decimal places (examples: 1.2374 would round to 1.237 and 1.2375 would round to 1.238).
Leave a blank line after the output for each data set. Follow the format illustrated in Sample Output.

1.题目大意:在x轴上给出一系列灯的坐标,给出灯照射出等腰三角形范围的顶角的一半。定义某点的灯光强度为初始光强I/d,d为灯坐标到点的距离,问给定点的灯光强度之和

2.这题也是比较有毒的一道题,像我上面说的那样,angle/PI*180能过但是angle/180*PI过不了。很邪乎,无非就是求出点和每个灯那里的竖直线夹角再和给定角度比较,无语的一道题

#include <iostream>
#include <math.h>
using namespace std;
#define Point Vector
const double PI=3.14159265;
const double eps=1e-2;

int dcmp(double d){  
	if(fabs(d)<eps) return 0;
	return d>0?1:-1;
}

struct Point{
    double x,y;
    Point(double a=0,double b=0):x(a),y(b){}

    Vector operator + (Vector B){
        return Vector(x+B.x,y+B.y);
    }

    Vector operator - (Point B){
        return Vector(x-B.x,y-B.y);
    }

    Vector operator * (double d){
        return Vector(x*d,y*d);
    }

    double operator * (Vector B){ 
        return x*B.x+y*B.y;
    }

    Vector operator / (double d){
        return Vector(x/d,y/d);
    }

    double operator ^ (Vector B){ 
        return x*B.y-y*B.x;
    }

    bool operator < (const Point &b) const {
        if(x==b.x) return y<b.y;
        return x<b.x;
    }

    bool operator == (const Point& b) const {
        if(dcmp(x-b.x)==0 && dcmp(y-b.y)==0)
            return true;
        return false;
    }
};

double dis(Vector A){
    return A*A;
}


double x[1005];
double ang[1005];
double I[1005];

int main()
{
    int t,n;
    double a,b,c,d;
    scanf("%d",&t);
    for(int kase=1;kase<=t;kase++){
        scanf("%lf%lf%d",&a,&b,&n);
        for(int i=1;i<=n;i++){
            scanf("%lf",&x[i]);
        }
        for(int i=1;i<=n;i++){
            scanf("%lf",&ang[i]);
        }
        for(int i=1;i<=n;i++)
            scanf("%lf",&I[i]);
        double ans=0.0;
        for(int i=1;i<=n;i++){
            double ang1=atan(fabs(a-x[i])/b);
            ang1=ang1/PI*180;
            //double ang2=ang[i]*PI/180    //WA!!!
            if(dcmp(ang[i]-ang1)>=0){
                d=dis(Point(a-x[i],b));
                ans+=I[i]/d;
            }
        }
        printf("Scene #%d: Spotlight intensity on Stacie is %.3lf\n\n",kase,ans);
    }
    return 0;
}

I - Ty G. Too?(简单计算几何)

题目链接

1.计算两个圆的面积和相邻区域的面积

2.签到题而已,整成0.13的通过率我也是服了。为什么double不能过呢?脚做的数据

#include <iostream>
#include <math.h>
using namespace std;
const double PI=3.14159;


int main()
{
    int n;
    float a,b,c;
    //ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    scanf("%d",&n);
    for(int k=1;k<=n;k++){
        scanf("%f%f",&a,&b);
        c=a-b;
        float res=PI*(a*a-b*b-c*c)/2;
        float s1=PI*b*b+res;
        float s2=PI*c*c+res;
        printf("Taijitu #%d: yin %.2f, yang %.2f\n\n",k,s2,s1);
    }
    return 0;
}
发布了128 篇原创文章 · 获赞 7 · 访问量 5247

猜你喜欢

转载自blog.csdn.net/qq_44691917/article/details/104813052