NENU Summer Training 2014 #8

Ignatius

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status Practice HDU 1073

Description

Ignatius is building an Online Judge, now he has worked out all the problems except the Judge System. The system has to read data from correct output file and user‘s result file, then the system compare the two files. If the two files are absolutly same, then the Judge System return "Accepted", else if the only differences between the two files are spaces(‘ ‘), tabs(‘\t‘), or enters(‘\n‘), the Judge System should return "Presentation Error", else the system will return "Wrong Answer".

Given the data of correct output file and the data of user‘s result file, your task is to determine which result the Judge System will return.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. 
Each test case has two parts, the data of correct output file and the data of the user‘s result file. Both of them are starts with a single line contains a string "START" and end with a single line contains a string "END", these two strings are not the data. In other words, the data is between the two strings. The data will at most 5000 characters.

Output

For each test cases, you should output the the result Judge System should return.

Sample Input

4 START 1 + 2 = 3 END START 1+2=3 END START 1 + 2 = 3 END START 1 + 2 = 3 END START 1 + 2 = 3 END START 1 + 2 = 4 END START 1 + 2 = 3 END START 1 + 2 = 3 END

Sample Output

Presentation Error Presentation Error Wrong Answer Presentation Error

分析:

最好的方法就是将输入的数组去除空行  \n,\t然后再两两进行比较

代码:

#include<stdio.h>
#include<string.h>

const int maxn=5001;
char s1[maxn],s2[maxn];

void input(char *s)
{
    char temp[maxn];
    gets(temp);
    while(strcmp(temp,"START")!=0)
          gets(temp);
    while(gets(temp))
    {
        if(strcmp(temp,"END")==0)
            break;
        if(strlen(temp)!=0)
            strcat(s,temp);
        strcat(s,"\n");
     }
}

void del(char *s,int l)
{
    char temp[maxn];
    int i,j;
    j=0;
    for(i=0;i<l;i++)
    {
        if(s[i]!=‘ ‘&&s[i]!=‘\n‘&&s[i]!=‘\t‘)
            temp[j++]=s[i];
    }
    temp[j]=‘\0‘;
    strcpy(s,temp);
}

int sum()
{
    int l1,l2;
    l1=strlen(s1);
    l2=strlen(s2);
    if(l1==l2&&strcmp(s1,s2)==0)
       return 1;
    del(s1,l1);
    del(s2,l2);
    if(strcmp(s1,s2)==0)
       return 0;
    else
       return -1;
}

int main()
{
    int T,count;
    scanf("%d",&T);
    while(T--)
    {
        input(s1);
        input(s2);
        count=sum();
        if(count==1)
           printf("Accepted\n");
        else if(count==0)
           printf("Presentation Error\n");
        else
           printf("Wrong Answer\n");
    }

    return 0;
}

#include<stdio.h>
#include<string.h>
const int maxn=5001;
char s1[maxn],s2[maxn],t1[maxn],t2[maxn];
char temp[maxn];

void input(char *s,char *t)
{
    gets(temp);
    while(strcmp(temp,"START")!=0)
          gets(temp);
    while(gets(temp))
    {
        if(strcmp(temp,"END")==0)
           break;
        if(strlen(temp)!=0)
           strcat(s,temp);
        strcat(s,"\n");
    }
    int k=0;
    int l=strlen(s);
    int i;
    for(i=0;i<l;i++)
    {
        if(s[i]!=‘ ‘&&s[i]!=‘\n‘&&s[i]!=‘\t‘)
            t[k++]=s[i];
    }
    t[k]=‘\0‘;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        s1[0]=‘\0‘;
        s2[0]=‘\0‘;
        input(s1,t1);
        input(s2,t2);
        if(strcmp(s1,s2)==0)
           printf("Accepted\n");
        else if(strcmp(t1,t2)==0)
            printf("Presentation Error\n");
        else
            printf("Wrong Answer\n");
    }
    return 0;
}

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#ifdef __int64
typedef __int64 LL;
#else
typedef long long LL;
#endif

const int inf=0x3f3f3f3f;
const int maxn=5050;

char t[maxn],as[maxn],bs[maxn],ap[maxn],bp[maxn];

int main()
{
    int n,ca,cb;
    scanf("%d",&n);
    getchar();
    while(n--)
    {
        gets(t);
        memset(t,0,sizeof(t));
        memset(as,0,sizeof(as));
        memset(bs,0,sizeof(bs));
        memset(ap,0,sizeof(ap));
        memset(bp,0,sizeof(bp));
        ca=cb=0;
        while(gets(t))
        {
            if(strcmp(t,"END")==0)
               break;
            strcat(as,t);
            ca++;
        }
        gets(t);
        while(gets(t))
        {
            if(strcmp(t,"END")==0)
                break;
            strcat(bs,t);
            cb++;
        }
        if(ca==cb&&strcmp(as,bs)==0)
            printf("Accepted\n");
        else
        {
            int la=strlen(as),lb=strlen(bs);
            int lla=0,llb=0;
            for(int i=0;i<la;i++)
            {
                if(as[i]!=‘ ‘&&as[i]!=‘\n‘&&as[i]!=‘\t‘)
                   ap[lla++]=as[i];
            }
            for(int i=0;i<lb;i++)
            {
                if(bs[i]!=‘ ‘&&bs[i]!=‘\n‘&&bs[i]!=‘\t‘)
                    bp[llb++]=bs[i];
            }
            if(strcmp(ap,bp)==0)
               printf("Presentation Error\n");
            else
               printf("Wrong Answer\n");
        }
    }
    return 0;
}

Parabola

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status Practice HDU 1071

Description

Ignatius bought a land last week, but he didn‘t know the area of the land because the land is enclosed by a parabola and a straight line. The picture below shows the area. Now given all the intersectant points shows in the picture, can you tell Ignatius the area of the land?

Note: The point P1 in the picture is the vertex of the parabola.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. 
Each test case contains three intersectant points which shows in the picture, they are given in the order of P1, P2, P3. Each point is described by two floating-point numbers X and Y(0.0<=X,Y<=1000.0).

Output

For each test case, you should output the area of the land, the result should be rounded to 2 decimal places.

Sample Input

2 5.000000 5.000000 0.000000 0.000000 10.000000 0.000000 10.000000 10.000000 1.000000 1.000000 14.000000 8.222222

Sample Output

33.33 40.69

Hint

 For float may be not accurate enough, please use double instead of float.
         

分析:

一道高数题 就是求出曲线和直线的方程在积分就好了!(曲线的方程可用顶点式  y = a(x-h)^2+l, (h,L) 为顶点坐标)

代码:

1.

设二次函数为y=a*x^2+b*x+c

(1)由于p1为二次函数顶点,所以b=-2*a*x1 (2)代入二次函数式子 1 里得y=a*x^2-2*a*x1*x+c(3)把p1,p2坐标代入 3 中,算出a,

然后由 2 算出b ,然后a、b、p3坐标代入 1 中算出c。这样下来就算出a、b、c了,那么ans=微积分求面积-梯形面积。

#include<stdio.h>
int main()
{
    int n;
    double x1,x2,x3,y1,y2,y3;
    double s,a,b,c,k,h;
    while(~scanf("%d",&n))
    {
        while(n--)
        {
            scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
            a=(y2-y1)/((x2-x1)*(x2-x1));
            b=-2*a*x1;
            c=y1-a*x1*x1-b*x1;
            k=(y2-y3)/(x2-x3);
            h=y2-k*x2;
            s=(a*(x3*x3*x3-x2*x2*x2)/3)+((b-k)*(x3*x3-x2*x2)/2)+((c-h)*(x3-x2));
            printf("%.2lf\n",s);
        }
    }
    return 0;
}

2.
这里我们设抛物线顶点式方程y=a*(x-h)^2+k;顶点坐标为(h,k)。h=x1;k=y1;a=(y-k)/(x-h)^2;

由积分可得(x2,x3)之间的面积,再减去梯形的面积即可

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <cmath>
using namespace std;

#ifdef __int64
typedef __int64 LL;
#else
typedef long long LL;
#endif

const int inf = 0x3f3f3f3f;
const int maxn = 100000;

int main() {
    int n;
    double x1,y1,x2,y2,x3,y3;
    scanf("%d",&n);
    while(n--) {
        scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
        double b=x1;
        double c=y1;
        double a=(y2-c)/(x2-b)/(x2-b);
        double k=(y3-y2)/(x3-x2);
        double b1=y2-k*x2;
        double s1=a*x3*x3*x3/3-(2*a*b+k)*x3*x3/2+(a*b*b+c-b1)*x3;
        double s2=a*x2*x2*x2/3-(2*a*b+k)*x2*x2/2+(a*b*b+c-b1)*x2;
        printf("%.2f\n",s1-s2);
    }
    return 0;
}

时间: 2024-07-28 13:29:30

NENU Summer Training 2014 #8的相关文章

(诡异Floyd&amp;自环)MZ Training 2014 #15 E题(POJ 2240)

你们见过这么诡异的FLOYD吗? 先上题. [Description] 货币的汇率存在差异,例如,假设1美元购买0.5英镑,1英镑买10法郎,而1法国法郎买0.21美元.然后,通过转换货币,一个聪明的交易者可以从1美元买0.5 * 10 * 0.21 = 1.05美元,获利5%. 你的任务是写一个程序,以一个货币汇率列表的作为输入,然后确定能不能获利. [Intput] 输入包含多组测试数据,每组数据第一行一个数n(1<=n<=30),表示有n中货币,接下来n行,每行一种货币名称,名称内不会出

2014 Multi-University Training Contest 6 Apple Tree(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 176    Accepted Submission(s): 120 Problem Description I've bought an orchard an

2014 Super Training #1 F Passage 概率DP

原题: HDU 3366   http://acm.hdu.edu.cn/showproblem.php?pid=3366 本来用贪心去做,怎么都WA,后来看网上原来是一个DP题. 首先按P/Q来做排序,即P越大,Q越小就越好,这样可以确保先选最优的路走. dp[i][j]表示已经到了第i条路(说明前i-1条都没成功的情况),还剩j块钱时能够走出去的概率. 则方程: dp[i][j] = way[i].P + way[i].Q*(dp[i+1][j-1]) + way[i].D*(dp[i+1]

2014 UESTC Training for Data Structures H - Cookies Test

H - Cookies Test Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status As chief programmer at a cookie production plant you have many responsibilities, one of them being that the cookies produced and packag

2014 UESTC Training for Data Structures K - 方师傅与栈

K - 方师傅与栈 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status 方师傅有一个1?N的排列,排列的顺序是固定的,他想要把这个排列重新排列成他喜欢的顺序. 于是他买了一个栈,他会按顺序将排列扔进栈内,在某些时刻将栈顶元素取出,这样出栈后的排列就可以重新排序啦. 例如,原序列是1,2,他先将1入栈,再将2入栈,然后将2出栈,最后将1出栈,那么新序列就变

2014 UESTC Training for Data Structures J - 方师傅的01串

J - 方师傅的01串 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status 方师傅过生日啦,于是蟹毛买了N个01串,想送给方师傅. 但是蟹毛觉得这些01串不够美,于是他想从中选出一些送给方师傅. 蟹毛对于p个01串的美值定义为: 这些01串的最长公共前缀的长度×p 所以蟹毛想从N个01串中选出一些,使得这些01串的美值最高. 请告诉蟹毛最好的美值是多少.

2014 UESTC Training for Data Structures C - 东风不与周郎便

C - 东风不与周郎便 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status "揽二乔于东南兮,乐朝夕之与共" 一首铜雀台赋,将愤怒与恐惧散播在了孙吴大军之中. 对抗曹军,万事俱备,只欠东风. 现在已经找到n个风眼,这些风眼的东风有强有弱,诸葛亮说他每次祈风都能够将一段风眼的东风增强,但需人去帮他布阵.同时他需要时刻掌控风眼的状况,以确定下一步的

2014 UESTC Training for Data Structures A - Islands

A - Islands Time Limit: 30000/10000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status Deep in the Carribean, there is an island even stranger than the Monkey Island, dwelled by Horatio Torquemada Marley. Not only it has a re

UESTC 2014 Summer Training #19

A.UVALive 6161 去迟了,队友已经开始写了,应该是个水题,贴个队友代码 #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<map> #include<set> #include<vector> #include<algorithm> #inclu