2012天津现场赛两个水题
2013-08-18 20:19
246 查看
H题:hdu 4438
这个题目是我刚刚弄ACM的时候做的一道题目。这是一个很简单的思维问题,但是当时没有用double,然后就一直WA。自己当时做这个题目花了一个小时左右吧,毕竟当时刚了解,记忆犹新啊!然后看到tiger,wolf.立马就想起来了。
题目地址:Hunters
AC代码:
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
int n;
double x,y,p,q,res1,res2;
scanf("%d",&n);
while(n--)
{
scanf("%lf%lf%lf%lf",&x,&y,&p,&q);
res1=q*(p*x+p*y)+(1-q)*x; //A先选择tiger
res2=q*y+(1-q)*(p*y+p*x); //A先选择wolf
if(res1>res2)
printf("tiger %.4lf\n",res1);
else
printf("wolf %.4lf\n",res2);
}
return 0;
}
B题:hdu 4432
就一个进制转换的简单题目,当时应该我坚持写的,然后吉吉继续写他的麻将。用到一个思路,就是找因子的时候,只需要找sqrt(n+0.5)以内的,如果a是因子,n/a必将也是因子。25=5*5这样的需要判断下。先把所有的和求出来,然后再转换进制。不过后来吉吉把麻将A了,很是HAPPY!不过我们也需要看到自己的弱点。掌握的知识还是远远不够。
题目地址:Sum of divisors
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int n,base;
int a[1002],pa;
int cal(int t) //计算每个因子的位数平方和
{
int ans=0;
while(t)
{
int tmp=t%base;
ans+=tmp*tmp;
t/=base;
}
return ans;
}
void fun(int t) //将最后的sum保存到数组a中
{
pa=-1;
while(t)
{
int tmp=t%base;
a[++pa]=tmp;
t/=base;
}
}
int main()
{
int i,p,sum;
while(~scanf("%d%d",&n,&base))
{
p=sqrt(n+0.5);
sum=0;
for(i=1;i<=p;i++)
{
if(n%i==0)
{
if(i*i==n) sum+=cal(i); //25=5*5; 5只能算一遍
else sum+=cal(i)+cal(n/i);
}
}
fun(sum);
for(i=pa;i>=0;i--)
{
if(a[i]<10)
cout<<a[i];
else //大于10的输出A~F
{
char c=a[i]-10+'A';
cout<<c;
}
}
cout<<endl;
}
return 0;
}
这个题目是我刚刚弄ACM的时候做的一道题目。这是一个很简单的思维问题,但是当时没有用double,然后就一直WA。自己当时做这个题目花了一个小时左右吧,毕竟当时刚了解,记忆犹新啊!然后看到tiger,wolf.立马就想起来了。
题目地址:Hunters
AC代码:
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
int n;
double x,y,p,q,res1,res2;
scanf("%d",&n);
while(n--)
{
scanf("%lf%lf%lf%lf",&x,&y,&p,&q);
res1=q*(p*x+p*y)+(1-q)*x; //A先选择tiger
res2=q*y+(1-q)*(p*y+p*x); //A先选择wolf
if(res1>res2)
printf("tiger %.4lf\n",res1);
else
printf("wolf %.4lf\n",res2);
}
return 0;
}
B题:hdu 4432
就一个进制转换的简单题目,当时应该我坚持写的,然后吉吉继续写他的麻将。用到一个思路,就是找因子的时候,只需要找sqrt(n+0.5)以内的,如果a是因子,n/a必将也是因子。25=5*5这样的需要判断下。先把所有的和求出来,然后再转换进制。不过后来吉吉把麻将A了,很是HAPPY!不过我们也需要看到自己的弱点。掌握的知识还是远远不够。
题目地址:Sum of divisors
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int n,base;
int a[1002],pa;
int cal(int t) //计算每个因子的位数平方和
{
int ans=0;
while(t)
{
int tmp=t%base;
ans+=tmp*tmp;
t/=base;
}
return ans;
}
void fun(int t) //将最后的sum保存到数组a中
{
pa=-1;
while(t)
{
int tmp=t%base;
a[++pa]=tmp;
t/=base;
}
}
int main()
{
int i,p,sum;
while(~scanf("%d%d",&n,&base))
{
p=sqrt(n+0.5);
sum=0;
for(i=1;i<=p;i++)
{
if(n%i==0)
{
if(i*i==n) sum+=cal(i); //25=5*5; 5只能算一遍
else sum+=cal(i)+cal(n/i);
}
}
fun(sum);
for(i=pa;i>=0;i--)
{
if(a[i]<10)
cout<<a[i];
else //大于10的输出A~F
{
char c=a[i]-10+'A';
cout<<c;
}
}
cout<<endl;
}
return 0;
}
相关文章推荐
- 2012天津regional的五道水题(ABCEH)
- hdu 4435 2012天津现场赛
- 2012金华现场赛四个水题题解(积分赛第四场)
- 2012天津现场赛
- 【2012天津区域赛】部分题解 hdu4431—4441
- Faulty Odometer--2012天津网络赛--数位dp
- 华为2012校园招聘上机题——大数相乘,两个超过100位的大数相乘C语言
- hdu 5538 House Building(长春现场赛——水题)
- 2012 天津网络赛小记
- 两个学生的Esri 2012中国用户大会
- VS2012 将两个项目合并在一个项目中使用
- HDU 4435 charge-station (2012年天津赛区现场赛E题)
- 2012 金华现场赛 A题
- 2012 金华现场赛K题
- 英雄会第二届在线编程大赛·CSDN现场决赛:三元组的数量【水题】
- 【2015-2016 ACM-ICPC Pacific Northwest Regional Contest (Div 1)D】【水题】Triangle 两个三角形是否可以恰好拼成矩形
- CF 1A1B 两个水题(简单思维+细心)
- 2012天津网络赛
- ZOJ 2819 Average Score 牡丹江现场赛A题 水题/签到题
- 2012百度之星资格赛 J:百度的新大厦(不是水题胜似水题)