1001 Drink
地址:http://acm.hdu.edu.cn/showproblem.php?pid=6743
给出
n
n
n瓶饮料,第
i
i
i瓶饮料提供
x
[
i
]
x[i]
x[i]的水分和
y
[
i
]
y[i]
y[i]的卡路里。我们现在要补充
m
m
m的水分,选定一瓶饮料就一直喝直到补充到足够的水分。一瓶饮料打开就必须全喝。我们现在要找到我们能补充的最小的卡路里。
显然我们只要输入一瓶饮料的
x
x
x值和
y
y
y值,就能直接得到结果。取最小即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int test,n,m,x,y,ans,tmp;
int main(){
scanf("%d",&test);
while(test--){
scanf("%d%d",&n,&m);
ans=1e9+7;
for(int i=0;i<n;i++){
scanf("%d%d",&x,&y);
tmp=m%x==0?m/x:m/x+1;
ans=min(ans,tmp*y);
}
printf("%d\n",ans);
}
return 0;
}
1002 GPA
地址:http://acm.hdu.edu.cn/showproblem.php?pid=6744
这个题给出总分,让你通过总分找最优绩点能是多少。
数据量只有400,显然很适合打表,根据题意打表即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
double ans[405]={0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.7,1.7,1.7,2.0,2.0,2.3,2.3,2.3,2.7,2.7,2.7,2.7,2.7,3.0,3.0,3.0,3.0,3.0,3.3,3.3,3.3,3.3,3.3,3.7,3.7,3.7,3.7,3.7,4.0,4.0,4.0,4.0,4.0,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.3,4.4,4.4,4.6,4.7,4.7,5.0,5.0,5.0,5.4,5.4,5.4,5.4,5.4,5.7,5.7,5.7,5.7,5.7,6.0,6.0,6.0,6.0,6.0,6.4,6.4,6.4,6.4,6.4,6.7,6.7,6.7,6.7,6.7,7.0,7.0,7.0,7.0,7.0,7.4,7.4,7.4,7.4,7.4,7.7,7.7,7.7,7.7,7.7,8.0,8.0,8.0,8.0,8.0,8.3,8.3,8.3,8.3,8.3,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.6,8.7,8.7,8.7,8.7,8.7,9.1,9.1,9.1,9.1,9.1,9.4,9.4,9.4,9.4,9.4,9.7,9.7,9.7,9.7,9.7,10.1,10.1,10.1,10.1,10.1,10.4,10.4,10.4,10.4,10.4,10.7,10.7,10.7,10.7,10.7,11.1,11.1,11.1,11.1,11.1,11.4,11.4,11.4,11.4,11.4,11.7,11.7,11.7,11.7,11.7,12.0,12.0,12.0,12.0,12.0,12.3,12.3,12.3,12.3,12.3,12.6,12.6,12.6,12.6,12.6,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,12.9,13.1,13.1,13.1,13.1,13.1,13.4,13.4,13.4,13.4,13.4,13.8,13.8,13.8,13.8,13.8,14.1,14.1,14.1,14.1,14.1,14.4,14.4,14.4,14.4,14.4,14.8,14.8,14.8,14.8,14.8,15.1,15.1,15.1,15.1,15.1,15.4,15.4,15.4,15.4,15.4,15.7,15.7,15.7,15.7,15.7,16.0,16.0,16.0,16.0,16.0,16.3,16.3,16.3,16.3,16.3,16.6,16.6,16.6,16.6,16.6,16.9,16.9,16.9,16.9,16.9,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2,17.2};
int t,n;
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
printf("%.1lf\n",ans[n]);
}
return 0;
}
1003 Dec
地址:http://acm.hdu.edu.cn/showproblem.php?pid=6745
给出
a
a
a和
b
b
b两个整数,每次操作可以选一个大于1的数减一,问直到
a
a
a和
b
b
b都变为1,这个过程中这两个数互质的次数最多是多少。
根据题目可知两个数最大到
1000
1000
1000,但是询问次数到了
1
e
6
1e6
1e6,所以暴力不可取。我们发现预处理出所有结果的复杂度是完全可取的。我们发现
a
a
a和
b
b
b的互质次数是
m
m
m,那么
a
+
1
a+1
a+1和
b
b
b以及
a
a
a和
b
+
1
b+1
b+1的互质次数至少也是
m
m
m。如果加一之后还互质,结果加一即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int test,a,b,dp[1005][1005];
int main(){
dp[1][1]=1;
for(int i=1;i<=1000;i++){
for(int j=1;j<=1000;j++){
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
if(__gcd(i,j)==1) dp[i][j]++;
dp[j][i]=dp[i][j];
}
}
scanf("%d",&test);
while(test--){
scanf("%d%d",&a,&b);
printf("%d\n",dp[a][b]);
}
return 0;
}