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[]= {,,,,};
int r[]= {,,,,};
double gpa[]= {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==&&a<=sum&&b>=sum)
{
mingpa=c;
flag=true;
return ;
}
if(t1>||t2==) return ;
for(int i=t2; i>=; i--)
{
dfs1(t1+,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==&&a<=sum&&b>=sum)
{
maxgpa=c;
flag=true;
return ;
}
if(t1<||t2==) return ;
for(int i=t2; i>=; i--)
{
dfs2(t1-,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=; flag=false;
dfs1(,N,,,);
flag=false;
dfs2(,N,,,);
printf("%.4lf %.4lf\n",mingpa/N,maxgpa/N);
}
return ;
}

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

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

  1. HDU 4968 Improving the GPA(dp)

    HDU 4968 Improving the GPA 题目链接 dp.最大最小分别dp一次,dp[i][j]表示第i个人,还有j分的情况,分数能够减掉60最为状态 代码: #include <c ...

  2. HDOJ(1010)DFS+剪枝

    Tempter of the Bone http://acm.hdu.edu.cn/showproblem.php?pid=1010 #include <stdio.h> #include ...

  3. POJ2676 – Sudoku(数独)—DFS

    Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24081   Accepted: 11242   Specia ...

  4. LeetCode 5215. 黄金矿工(Java)DFS

    题目: 5215. 黄金矿工 你要开发一座金矿,地质勘测学家已经探明了这座金矿中的资源分布,并用大小为 m * n 的网格 grid 进行了标注.每个单元格中的整数就表示这一单元格中的黄金数量:如果该 ...

  5. Java实现 蓝桥杯 算法提高 GPA(暴力)

    试题 算法提高 GPA 问题描述 输入A,B两人的学分获取情况,输出两人GPA之差. 输入格式 输入的第一行包含一个整数n表示A的课程数,以下n行每行Si,Ci分别表示第i个课程的学分与A的表现. G ...

  6. BZOJ 1064 假面舞会(NOI2008) DFS判环

    此题,回想Sunshinezff学长给我们出的模拟题,原题啊有木有!!此处吐槽Sunshinezff爷出题不人道!! 不过也感谢Sunshinezff学长的帮助,我才能做出来.. 1064: [Noi ...

  7. How far away ?(LCA)dfs和倍增模版

    How far away ? Tarjan http://www.cnblogs.com/caiyishuai/p/8572859.html Time Limit: 2000/1000 MS (Jav ...

  8. 步步为营(十五)搜索(一)DFS 深度优先搜索

    前方大坑预警! 先讲讲什么是搜索吧. 有一天你去一个果园摘梨子,果农告诉你.有一棵树上有一个金子做的梨子,找到就是你的,你该怎么找? 地图例如以下: S 0 0 0 0 0 0 0 0 0 0 0 0 ...

  9. 深度优先搜索(Depth-First-Search)dfs代码模板

    void dfs()//参数用来表示状态 { if(到达终点状态) { ...//根据需求添加 return; } if(越界或者是不合法状态) return; if(特殊状态)//剪枝,去除一些不需 ...

随机推荐

  1. Python -bs4介绍

    https://cuiqingcai.com/1319.html Python -BS4详细介绍Python 在处理html方面有很多的优势,一般情况下是要先学习正则表达式的.在应用过程中有很多模块是 ...

  2. php防sql注入过滤代码

    防止sql注入的函数,过滤掉那些非法的字符,提高sql安全性,同时也可以过滤XSS的攻击. function filter($str) { if (empty($str)) return false; ...

  3. VS 快捷键设置

    工具 --> 选项 --> 环境 --> 键盘

  4. html-文件上传设置accept类型延时问题

       今天在做文件上传时,采用了jQuery的upload插件,使用过程中发现了一个很有意思也很头疼的问题. 上传按钮,第一次点击时瞬间就可以打开文件选择框,之后再点击则需要等待恐怖的8s以上. 百度 ...

  5. github或码云协同开发

    协同开发 1.引子:假如三个人共同开发同一份代码,每个人都各自安排了任务,当每个人都完成了一半的时候,提交不提交呢? 要提交,提交到dev吗,都上传了一半,这样回家拿出来的代码根本跑不起来.所以, 为 ...

  6. python读取文件首行和最后一行

    python读取文件最后一行两种方式 1)常规方法:从前往后依次读取 步骤:open打开文件. 读取文件,把文件所有行读入内存. 遍历所有行,提取指定行的数据. 优点:简单,方便 缺点:当文件大了以后 ...

  7. [LeetCode] 206. Reverse Linked List_Easy tag: Linked List

    Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4-> ...

  8. One difference between AngularJS' $location and window.location

    Recenently, I encountered a problem. Client side code is: $http({ url: "/api/runtimelicense&quo ...

  9. 前端基础——css

    前端基础——css css的内容主要包括:盒子模型.定位.单位与取值.属性.选择器.

  10. centos6 Linux安装redis 2.6.14

    1.获取安装文件 wget http://download.redis.io/redis-stable.tar.gz 2.解压文件 tar xzvf redis-stable.tar.gz 3.进入目 ...