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. Spring IOC 容器源码分析系列文章导读

    1. 简介 Spring 是一个轻量级的企业级应用开发框架,于 2004 年由 Rod Johnson 发布了 1.0 版本.经过十几年的迭代,现在的 Spring 框架已经非常成熟了.Spring ...

  2. Lerning Entity Framework 6 ------ Inserting, Querying, Updating, and Deleting Data

    Creating Entities First of all, Let's create some entities to have a test. Create a project Add foll ...

  3. OSLab文件描述符

      日期:2019/3/24 内容:Linux文件描述符.   一.基本概念 文件描述符(File Descriptor) 一个非负整数.应用程序利用文件描述符来访问文件.打开现存文件或新建文件时,内 ...

  4. Borrowed Time

    嘛,这是第一篇博客啦~ 应该会发知识点总结和题解一类的东西 当然也会拿这个博客当todolist使用了 希望自己可以变得更强吧

  5. C#6.0语言规范(十八) 不安全代码

    前面章节中定义的核心C#语言与C和C ++的区别在于它省略了作为数据类型的指针.相反,C#提供了引用和创建由垃圾收集器管理的对象的能力.这种设计与其他功能相结合,使C#成为比C或C ++更安全的语言. ...

  6. Tools - 浏览器Firefox

    简介 http://www.mozilla.org/ 中文官网:http://www.firefox.com.cn/ https://www.mozilla.org/zh-CN/firefox/ Mo ...

  7. 7-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案升级篇(TCP实现HTTP访问下载文件,明白底层如何实现的,地基稳才踏实)

    看了好多文章.....唉,还是自己亲自动手用网络监控软件测试吧 先看这个节安装WEB服务器.....安装好以后就可以用HTTP访问电脑文件了 6-STM32物联网开发WIFI(ESP8266)+GPR ...

  8. GCC C语言 DLL范例,含源码

    作者:小白救星 编译:gcc -c -DBUILDING_HZ_DLL1 hzdll1.c           gcc -shared -o hzdll1.dll hzdll1.o -Wl,--kil ...

  9. 课程一(Neural Networks and Deep Learning),第二周(Basics of Neural Network programming)—— 4、Logistic Regression with a Neural Network mindset

    Logistic Regression with a Neural Network mindset Welcome to the first (required) programming exerci ...

  10. 计算机网络 之 TCP和UDP的端口号解析

    前言:今天了解一下tcp和udp报文的端口.发现一直以来都只是知道端口用于区分同一IP的服务器的不同服务,已经端口的大小.在查找traceroute的资料的时候,才了解到一些之前没注意到的东西. (一 ...