Improving the GPA(hdu4968)dfs

Improving the GPA

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 206 Accepted Submission(s):
168

Problem Description

Xueba: Using the 4-Point Scale, my GPA is
4.0.

In fact, the AVERAGE SCORE of Xueba is calculated by the following
formula:
AVERAGE SCORE = ∑(Wi * SCOREi) / ∑(Wi)
1<=i<=N

where SCOREi represents the scores of the ith
course and Wi represents the credit of the corresponding course.

To
simplify the problem, we assume that the credit of each course is 1. In this
way, the AVERAGE SCORE is ∑(SCOREi) / N. In addition, SCOREi are all integers
between 60 and 100, and we guarantee that ∑(SCOREi) can be divided by
N.

In SYSU, the university usually uses the AVERAGE SCORE as the standard
to represent the students’ level. However, when the students want to study
further in foreign countries, other universities will use the 4-Point Scale to
represent the students’ level. There are 2 ways of transforming each score to
4-Point Scale. Here is one of them.

The
student’s average GPA in the 4-Point Scale is calculated as follows:GPA = ∑(GPAi) / N
So given one student’s AVERAGE
SCORE and the number of the courses, there are many different possible values in
the 4-Point Scale. Please calculate the minimum and maximum value of the GPA in
the 4-Point Scale.

Input

The input begins with a line containing an integer T (1
< T < 500), which denotes the number of test cases. The next T lines each
contain two integers AVGSCORE, N (60 <= AVGSCORE <= 100, 1 <= N <=
10).

Output

For each test case, you should display the minimum and
maximum value of the GPA in the 4-Point Scale in one line, accurate up to 4
decimal places. There is a space between two values.

Sample Input

4

75 1

75 2

75 3

75 10

Sample Output

3.0000 3.0000

2.7500 3.0000

2.6667 3.1667

2.4000 3.2000

Hint

In the third case, there are many possible ways to calculate the minimum value of the GPA in the 4-Point Scale.

For example,

Scores 78 74 73 GPA = (3.0 + 2.5 + 2.5) / 3 = 2.6667

Scores 79 78 68 GPA = (3.0 + 3.0 + 2.0) / 3 = 2.6667

Scores 84 74 67 GPA = (3.5 + 2.5 + 2.0) / 3 = 2.6667

Scores 100 64 61 GPA = (4.0 + 2.0 + 2.0) / 3 = 2.6667

题意:前面的都是废话,重要的是GPA = ∑(GPAi) / N,看懂这个和那张表就可以了,

   说白了,就是让你求平均绩点;

思路:最小的绩点就让成绩尽量往前靠,反之,最大的绩点就是让成绩尽量往后靠,这里指的是区间段;

ps:http://acm.hdu.edu.cn/showproblem.php?pid=4968

#include<stdio.h>
#include<string.h>
int l[5]= {60,70,75,80,85};
int r[5]= {69,74,79,84,100};
double gpa[5]= {2.0,2.5,3.0,3.5,4.0};

int avg,N,sum,P,Q;
double maxgpa,mingpa;
bool flag;

void dfs1(int t1,int t2,int a,int b,double c)
{
    if(flag) return ;
    if(t2==0&&a<=sum&&b>=sum)
    {
        mingpa=c;
        flag=true;
        return ;
    }
    if(t1>4||t2==0) return ;
    for(int i=t2; i>=0; i--)
    {
        dfs1(t1+1,t2-i,a+l[t1]*i,b+r[t1]*i,c+gpa[t1]*i);
    }
}
void dfs2(int t1,int t2,int a,int b,double c)
{
    if(flag) return ;
    if(t2==0&&a<=sum&&b>=sum)
    {
        maxgpa=c;
        flag=true;
        return ;
    }
    if(t1<0||t2==0) return ;
    for(int i=t2; i>=0; i--)
    {
        dfs2(t1-1,t2-i,a+l[t1]*i,b+r[t1]*i,c+gpa[t1]*i);
    }
}

int main()
{
    int T,i,j,k,l;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&avg,&N);
        sum=avg*N;
        maxgpa=mingpa=0;

        flag=false;
        dfs1(0,N,0,0,0);
        flag=false;
        dfs2(4,N,0,0,0);
        printf("%.4lf %.4lf\n",mingpa/N,maxgpa/N);
    }
    return 0;
}

dfs自己还用的不是很好,比赛的时候等我写完,我们队的其他人已经过了。。。。。

Improving the GPA(hdu4968)dfs

时间: 2024-10-08 10:14:04

Improving the GPA(hdu4968)dfs的相关文章

HDU 4968 Improving the GPA(dp)

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

hdu 4968 Improving the GPA(暴力枚举)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4970 Problem Description Xueba: Using the 4-Point Scale, my GPA is 4.0. In fact, the AVERAGE SCORE of Xueba is calculated by the following formula: AVERAGE SCORE = ∑(Wi * SCOREi) / ∑(Wi) 1<=i<=N where S

(二)Android性能优化系列---Improving Layout Performance(一)(转载自:http://xhmj12.iteye.com/blog/2064258)

Android性能优化系列---Improving Layout Performance(一) Layouts是Android应用里直接影响用户体验的一个关键部分.如果Layout设计的不好,可能导致你的应用大量的内存占用从而导致UI响应很慢.Android SDK提供了工具帮助你分析你的Layouts的性能问题.结合这个工具同时查看本文,你能实现滑动流畅.占用内存最小的用户界面. Use the <merge> Tag 某些时候,自定义可重用的布局包含了过多的层级标签,比如我们需要在Line

poj Sudoku(数独) DFS

Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13665   Accepted: 6767   Special Judge Description Sudoku is a very simple task. A square table with 9 rows and 9 columns is divided to 9 smaller squares 3x3 as shown on the Figure.

2014省赛大总结(一) DFS 与 BFS

list里的元素以逗号隔开,以[]包围,其中元素的类型任意 官方一点的说:list列表是一个任意类型的对象的位置相关的有序集合.它没有固定的大小(1),通过对偏移量 (2)进行赋值以及其他各种列表的方法进行调用,能够修改列表的大小. (1)尽管列表没有固定的大小,Python仍不允许引用不存在的元素,超出列表末尾之外的索引会导致错误,赋值也是. (2)我们可以通过偏移量对列表进行索引,切片等操作,而且索引值可为负值. list的主要属性 <1>任意对象的有序集合(从左到右的顺序) <2&

迷宫寻宝(一)(dfs)

迷宫寻宝(一) 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 一个叫ACM的寻宝者找到了一个藏宝图,它根据藏宝图找到了一个迷宫,这是一个很特别的迷宫,迷宫里有N个编过号的门(N<=5),它们分别被编号为A,B,C,D,E.为了找到宝藏,ACM必须打开门,但是,开门之前必须在迷宫里找到这个打开这个门所需的所有钥匙(每个门都至少有一把钥匙),例如:现在A门有三把钥匙,ACM就必须找全三把钥匙才能打开A门.现在请你编写一个程序来告诉ACM,他能不能顺利的得到宝藏. 输入

(三)Android性能优化系列---Improving Layout Performance(二)转载自:http://xhmj12.iteye.com/blog/2064342

Loading Views On Demand 有时你的布局可能需要一些复杂却又很少被用到的视图.无论他们是item详情.进度指示器,或撤销的消息,你都可以在需要时加载这些视图,来减少内存使用量并加快渲染速度. Define a ViewStub ViewStub是一个没有尺寸大小并且不会在布局中嵌套或渲染任何东西的轻量级的视图.因此在视图层次展现或隐藏它的代价非常小.每一个ViewStub仅仅需要包含android:layout属性来展现指定的布局. 以下ViewStub是一个半透明的进度条.

迷宫问题(二)-DFS解决

递归过程会自动利用栈,可以大大简化过程 #include<stdio.h> #define N 10 int vis[N][N], done = 0; char maze[N][N + 1]; int dx[]={0,1,0,-1}; int dy[]={1,0,-1,0}; void dfs(int x, int y) { int i; if(done || maze[x][y] == '#' || vis[x][y]) return; if(maze[x][y] == 'E') { //e

【(博弈)dfs序+树状数组】BZOJ2819-Nim

[题目大意] 普通的Nim游戏为:两个人进行游戏,N堆石子,每回合可以取其中某一堆的任意多个,可以取完,但不可以不取.谁不能取谁输.这个游戏是有必胜策略的.现在对每一堆编号1,2,3,4,...n,在堆与堆间连边,没有自环与重边,从任意堆到任意堆都只有唯一一条路径可到达.然后他不停地进行如下操作:1.随机选两个堆v,u,询问若在v到u间的路径上的石子堆中玩Nim游戏,是否有必胜策略,如果有,vfleaking将会考虑将这些石子堆作为初始局面之一,用来坑玩家. 2.把堆v中的石子数变为k. [思路