you are my friend#Sample Output4AC代码如下:#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 Output1.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;}
新闻热点
疑难解答