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. CopyOnWriteArrayList源码解析(1)

    此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 注:在看这篇文章之前,如果对ArrayList底层不清楚的话,建议先去看看ArrayList源码解析. ht ...

  2. BZOJ 5281--[Usaco2018 Open]Talent Show(分数规划&单调队列&DP)

    5281: [Usaco2018 Open]Talent Show Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 79  Solved: 58[Sub ...

  3. centos清华源地址,ubuntu阿里云源

    清华这个源挺好用,替换原先/etc/yum.repos.d/CentOS-Base.repo, 然后运行 sudo yum makecache 生成缓存 centos6 [base] name=Cen ...

  4. SpringMvc 启动原理源码分析

    了解一个项目启动如何实现是了解一个框架底层实现的一个必不可少的环节.从使用步骤来看,我们一般是引入包之后,配置web.xml文件.官方文档示例的配置如下: <web-app> <se ...

  5. js基础知识--变量类型和变量计算

    提问: JS中使用typeof能得到的哪些类型 何时使用===何时使用== JS中有哪些内置函数 JS变量按照存储方式区分为哪些类型,并描述其特点 如何理解JSON 涉及知识点:(1)变量类型 值类型 ...

  6. 【xsy2818】 最近点 动态树分治+可持久化线段树

    题目大意:给你一颗n个节点的树,最初点集S为空. 有m次操作:往当前点集S中加入/删除一个点,询问点x至集合S中任意点的最小距离,回到第t次修改点集的操作后的状态. 数据范围:$n,m≤10^5$ 我 ...

  7. [每天解决一问题系列 - 0001] Javascript apply和 call对比

    相同点: 每个函数都包含这两个原生的方法 他们两个的效果是一样的,用于在特定的作用域下执行函数,本质上是设置函数内this对象的值. 不同点: 传入的参数类型不同 . apply(函数作用域,arra ...

  8. 性能优化中CPU、内存、磁盘IO、网络性能的依赖(转)

    关于系统性能优化,推荐一篇不错的博客! 系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长期和持续的过程,不 是说现在优化了,测试 ...

  9. MapReduce中的partitioner

    1.日志源文件: 1363157985066 13726230503 00-FD-07-A4-72-B8:CMCC 120.196.100.82 i02.c.aliimg.com 24 27 2481 ...

  10. 再学C/C++ 之 浅析gdb的-g选项

    浅析gdb的-g选项   准备 gdb是Linux下学习C/C++最常用的debug工具.要使用这一强大工具,必须在编译时加上-g选项,生成的目标文件才可以用gdb进行调试. 如,先创建一个test. ...