您的位置:首页 > 其它

poj水题若干道

2014-07-15 21:35 204 查看
poj1033 Hangover

题目链接:http://poj.org/problem?id=1003

///2014.7.15
///poj1003

//Accepted    740K    0MS G++ 385B    2014-07-15 19:58:59

//题目大意:已知c=1/2+1/3+1/4+....1/(n+1).现给出一个值m,求n的值使得c刚好超过m。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
double num;
double sum;
int n;
while( cin>>num && num!=0 ){
n = 2;
sum = 0;
while( sum < num ){
sum += 1.0/n;
n++;
}
printf("%d card(s)\n",n-2 );
}
return 0;
}


poj1004 Financial Management

题目链接:http://poj.org/problem?id=1004

///2014.7.15
///poj1004

//题目大意:给出12个数,求这12个数的平均数。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
double sum = 0;
double num;
int n = 12;
while( n-- ){
cin>>num;
sum += num;
}
cout<<"$"<<sum/12<<endl;
return 0;
}


poj1005 I Think I Need a Houseboat

题目链接:http://poj.org/problem?id=1005

///2014.7.15
///poj1005

//题目大意:已知一个圆心为(0,0),
//半径随时间增长的位于X轴上方的半圆,
//初始面积为0,每年的面积增加50,给出一个坐标
//求该坐标在第几年被该半圆覆盖。

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

int main(){
// freopen("in","r",stdin);
// freopen("out","w",stdout);

int cas = 0;
int t;
scanf("%d",&t);
double x,y,Area;
while( t-- ){
cas++;
cin>>x>>y;
Area = (x*x+y*y) * 3.141592654 / 2;
int n = 0;
while( n*50 < Area )
n++;
cout<<"Property "<<cas<<": This property will begin eroding in year "<<n<<"."<<endl;
}
cout<<"END OF OUTPUT."<<endl;
return 0;
}


poj1207 The 3n + 1 problem

题目链接:http://poj.org/problem?id=1207

///2014.7.15
///poj1207

// 大致题意:
// 根据给定的算法,可以计算一个整数的循环数
// 现在给定一个区间,计算这个区间的所有数的循环数,把最大的循环数输出
// PS:输出的是整数A的循环数,而不是输出整数A

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

int cnum(int i){
int re = 1;
while( i!=1 ){
if( i%2 )
i = i*3+1;
else
i = i/2;
re++;
}
return re;
}

int main(){
// freopen("in","r",stdin);
// freopen("out","w",stdout);

int a,b;
int maxcnum;
while( cin>>a>>b ){
int x=a<b?a:b;
int y=a>b?a:b;
maxcnum = 0;
for(int i=x ; i<=y ; i++){
int temp = cnum(i);
if( temp > maxcnum )
maxcnum = temp;
}
cout<<a<<' '<<b<<' '<<maxcnum<<endl;
}
return 0;
}


poj3299 Humidex

题目链接:http://poj.org/problem?id=3299

#include <iostream>
#include <math.h>
#include <string>
#include <iomanip>
using namespace std;

int main(){
char alpha;
double t,d,h;
int i;
while( true ){
t=d=h=200;
for(i=0;i<2;i++)
{
cin>>alpha;
if(alpha=='E')
return 0;
else if(alpha=='T')
cin>>t;
else if(alpha=='D')
cin>>d;
else if(alpha=='H')
cin>>h;
}
if( h == 200 )
h=t+0.5555*(6.11*exp(5417.7530*(1/273.16-1/(d+273.16)))-10);
else if(t==200)
t=h-0.5555*(6.11*exp(5417.7530*(1/273.16-1/(d+273.16)))-10);
else if(d==200)
d=1/((1/273.16)-((log((((h-t)/0.5555)+10.0)/6.11))/5417.7530))-273.16;
cout<<setprecision(1)<<fixed<<"T "<<t<<" D "<<d<<" H "<<h<<endl;
}
return 0;
}


poj2159 Ancient Cipher

题目链接:http://poj.org/problem?id=2159

思路:只要原字符串跟加密之后的字符串能够一一对应,并且每个字符对应的字符不同即可。

///2014.7.16
///poj2159

//Accepted  704K    63MS    G++ 797B    2014-07-16 09:45:12

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

int main(){
// freopen("in","r",stdin);
// freopen("out","w",stdout);

string x,y;
char xnum[26],ynum[26];
for(int i=0 ; i<26 ; i++)
xnum[i] = ynum[i] = 0;
cin>>x>>y;
for(int i=0 ; i<x.length() ; i++)
xnum[ x[i]-'A' ] ++;
for(int i=0 ; i<y.length() ; i++)
ynum[ y[i]-'A' ] ++;
sort(xnum,xnum+26);
sort(ynum,ynum+26);
bool can = true;
for(int i=0 ; i<26 ; i++){
if( xnum[i] != ynum[i] ){
can = false;
break;
}
}
if( can )
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
return 0;
}


poj3094 Quicksum 很水很水

题目链接:http://poj.org/problem?id=3094

///2014.7.17
///poj3094

//Accepted    380K    0MS G++ 454B    2014-07-17 16:02:43

#include <cstdio>

char temp;
int sum;

int main(){
while( ~scanf("%c",&temp) && temp!='#' ){
int i=1;
sum = 0;
while( temp==' ' || ( temp<='Z' && temp>='A' ) ){
if( temp<='Z' && temp>='A' )
sum += (i++) * ( temp-'A'+1 );
else
i++;
scanf("%c",&temp);
}
printf("%d\n",sum );
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: