杭电2072 杭电2073 单词数 无限的路

来源:互联网 发布:linux多线程机制 编辑:程序博客网 时间:2024/05/18 01:20

Problem Description

lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。

Input
有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。

Output
每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。

Sample Input
you are my friend#

Sample Output
4
AC代码如下:
#include"iostream"#include "set"#include "string"using namespace std;int main(){    set<string> word;    char c='0';    string s;    while((c=getchar())!='#')    {        s="";        while(c!=' '&&c!='\n'&&c!='#')        {            s+=c;            c=getchar();        }        if (c=='#')        {            return 0;        }        if (s.length())        {            word.insert(s);        }        if (c=='\n')        {            cout<<word.size()<<endl;            word.clear();        }    }    return 0;}


Problem Description
甜甜从小就喜欢画图画,最近他买了一支智能画笔,由于刚刚接触,所以甜甜只会用它来画直线,于是他就在平面直角坐标系中画出如下的图形:



甜甜的好朋友蜜蜜发现上面的图还是有点规则的,于是他问甜甜:在你画的图中,我给你两个点,请你算一算连接两点的折线长度(即沿折线走的路线长度)吧。

Input
第一个数是正整数N(≤100)。代表数据的组数。
每组数据由四个非负整数组成x1,y1,x2,y2;所有的数都不会大于100。

Output
对于每组数据,输出两点(x1,y1),(x2,y2)之间的折线距离。注意输出结果精确到小数点后3位。

Sample Input
50 0 0 10 0 1 02 3 3 199 99 9 95 5 5 5

Sample Output
1.0002.41410.64654985.0470.000


分析:任意一点横纵坐标之和等于该点所在斜线的最高点的纵坐标

#include "iostream"#include "cmath"using namespace std;const double N=sqrt(2);int main(int argc, char* argv[]){    int n,i;    int x1,y1,x2,y2;    double a[200],b[200];    double res,z1,z2;    a[0]=0.0;    b[0]=0.0;    for (i=1;i<200;i++)    {        a[i]=a[i-1]+i*N;    }    for (i=1;i<200;i++)    {        b[i]=b[i-1]+sqrt((i-1)*(i-1)+i*i);    }    cin>>n;        while(n--)    {        cin>>x1>>y1>>x2>>y2;        if (x1==0&&y1==0)        {            z1=0;        }        else        {            z1=a[x1+y1-1]+b[x1+y1]+x1*N;            }        if (x2==0&&y2==0)        {            z2=0;        }        else        {            z2=a[x2+y2-1]+b[x2+y2]+x2*N;            }        res=fabs(z1-z2);        printf("%.3lf\n",res);    }    return 0;}

0 0
原创粉丝点击