HDU 4968 Improving the GPA(dp),hdu4968

來源:互聯網
上載者:User

HDU 4968 Improving the GPA(dp),hdu4968
HDU 4968 Improving the GPA

題目連結

dp,最大最小分別dp一次,dp[i][j]表示第i個人,還有j分的情況,分數可以減掉60最為狀態

代碼:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int t, avg, n;double dp1[15][405], dp2[15][405];double get(int x) {    if (x >= 25 && x <= 40) return 4.0;    if (x >= 20 && x <= 24) return 3.5;    if (x >= 15 && x <= 19) return 3.0;    if (x >= 10 && x <= 14) return 2.5;    return 2.0;}void init() {    for (int i = 1; i <= 400; i++)dp2[0][i] = 50;    for (int i = 1; i <= 10; i++) {for (int j = 0; j <= 400; j++) {    dp1[i][j] = 0;    dp2[i][j] = 50;    for (int k = 0; k <= j && k <= 40; k++) {dp1[i][j] = max(dp1[i][j], dp1[i - 1][j - k] + get(k));dp2[i][j] = min(dp2[i][j], dp2[i - 1][j - k] + get(k));    }}    }}int main() {    init();    scanf("%d", &t);    while (t--) {scanf("%d%d", &avg, &n);avg = (avg - 60) * n;printf("%.4lf %.4lf\n", dp2[n][avg] / n, dp1[n][avg] / n);    }    return 0;}



杭電ACM Steps 127 GPA

#include <stdio.h>
#include <string.h>
int main(){
int j,t,f,i,s;
char a[1000];
while(gets(a)!=NULL){
s=0;i=0;f=1;
for(j=0;j<strlen(a);j++){
if(a[j]!=' '){
switch(a[j]){
case 'A':t=4;i++;break;
case 'B':t=3;i++;break;
case 'C':t=2;i++;break;
case 'D':t=1;i++;break;
case 'F':t=0;i++;break;
default: f=0;break;
}
s=s+t;}}

if(f==1)
printf("%.2f\n",s*1.0/i);
else
printf("Unknown letter grade in input\n");
}
return 0;
}
 
杭電acm1201計算gpa的程式,一直提示ouput limit exceed

printf("%.2f\n",k);??

這是什麼。
最終結果 是輸出一個整數。你輸出了浮點數,

你寫的題目不是1201.
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.