GPA

Time Limit: 1000ms
Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 4406
64-bit integer IO format: %I64d      Java class name: Main

 
GPA(Grade-Point Average) is one way to measure students’ academic performance in PKU. Each course has an integer credit, ranges from 1 to 99. For each course, you will get a score at the end of the semester, which is an integer ranges from 0 to 100. Then you can calculate the Grade-Point of this course with the following formula. (Your score is x and your Grade-Point is p, using real arithmetic)

Then you can get the GPA with the following formula (the Grade-Point of course i is pi, and the credit of course i is wi).

Now it is not far from the final exam, if you do not review, you can only get a basic score in each course.

You have n days to review. There are K classes in each day. For each class, only one course can be reviewed. After the review, your score in this course will exactly increase by 1. You can get more increment by spending more classes in this course. But the score may not exceed 100.

For some reasons, not any course can be reviewed in any class. Each day you can only review some of the courses.

Now you want your GPA to be as high as possible, and at the same time, you do not want to fail in any course. Please calculate the highest GPA you can get.

 

Input

The input consists of several test cases. Each test case begins with 3 integers N (0<=N<=40), K(0<K<=20), M (0<M<=20), representing the number of days, the number of classes in each day and the number of courses. Next line contains M integers representing credits of each course and M integers representing basic scores of each course (0<=score<=100). Next N lines contain an N*M matrix, the jth element in ith row means whether you can review course j in ith day, 1 means you can review course j in ith day, 0 means you cannot. The Input ends with 0 0 0.

 

Output

For each test case, output the highest possible GPA, round to 6 digits after decimal point. If you have to fail a course, output 0.000000 instead.

 

Sample Input

2 10 3
1 1 2
50 60 90
1 1 0
1 0 1
2 20 4
1 1 1 1
50 50 50 40
1 1 1 0
0 0 0 1
0 0 0

Sample Output

2.757813
0.000000

Source

 
解题:最小费用最大流,最大费用最大流
 我们求最长路,所以越大越先被选!
为什么计算now - pre呢,因为分母是固定的,只要分子越大,GPA也就越大,我们贪心,优先选取使自己增幅大的,也就是now - pre增加大的。
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct arc {
int to,flow,next;
double cost;
arc(int x = ,int y = ,double z = ,int nxt = -) {
to = x;
flow = y;
cost = z;
next = nxt;
}
};
arc e[maxn<<];
int head[maxn],p[maxn],tot,S,T,n,k,m;
bool in[maxn];
double d[maxn];
int credit[maxn],basic[maxn],can[maxn][maxn];
void add(int u,int v,int flow,double cost) {
e[tot] = arc(v,flow,cost,head[u]);
head[u] = tot++;
e[tot] = arc(u,,-cost,head[v]);
head[v] = tot++;
}
bool spfa() {
for(int i = S; i <= T; ++i) {
d[i] = ;
p[i] = -;
in[i] = false;
}
queue<int>q;
q.push(S);
while(!q.empty()) {
int u = q.front();
q.pop();
in[u] = false;
for(int i = head[u]; ~i; i = e[i].next) {
if(e[i].flow && d[e[i].to] < d[u] + e[i].cost) {
d[e[i].to] = d[u] + e[i].cost;
p[e[i].to] = i;
if(!in[e[i].to]) {
in[e[i].to] = true;
q.push(e[i].to);
}
}
}
}
return p[T] > -;
}
void solve() {
while(spfa()) {
int minF = INF;
for(int i = p[T]; ~i; i = p[e[i^].to])
minF = min(minF,e[i].flow);
for(int i = p[T]; ~i; i = p[e[i^].to]) {
e[i].flow -= minF;
e[i^].flow += minF;
}
}
}
double calc(int x,int w){
return (4.0 - 3.0*( - x)*( - x)/1600.0)*w;
}
int main() {
while(scanf("%d %d %d",&n,&k,&m),n||m||k) {
memset(head,-,sizeof(head));
S = tot = ;
T = n + m + ;
int sum = ;
double ans = ;
for(int i = ; i <= m; ++i){
scanf("%d",credit+i);
sum += credit[i];
}
for(int i = ; i <= m; ++i)
scanf("%d",basic+i);
for(int i = ; i <= n; ++i) {
add(i+m,T,k,);
for(int j = ; j <= m; ++j) {
scanf("%d",can[i]+j);
if(can[i][j]) add(j,i+m,k,);
}
}
for(int i = ; i <= m; ++i) {
int h = basic[i];
if(h < ) {
add(S,i, - basic[i],INF);
h = ;
}
double pre = calc(h,credit[i]);
for(++h; h <= ; ++h){
double now = calc(h,credit[i]);
add(S,i,,now - pre);
pre = now;
}
}
solve();
for(int i = head[S]; ~i; i = e[i].next)
basic[e[i].to] += e[i^].flow;
bool flag = true;
for(int i = ; i <= m; ++i){
if(basic[i] < ){
flag = false;
break;
}
ans += calc(basic[i],credit[i])/sum;
}
printf("%.6f\n",flag?ans:);
}
return ;
}

HDU 4406 GPA的更多相关文章

  1. hdu 4802 GPA 水题

    GPA Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...

  2. HDU - 4802 - GPA (水题)

    题意: 计算GPA,输入一个数字和一个字符串,用 数字×字符串对应的数值 思路: 用map对应数值,要注意的是字符串为P或者N的时候,不计入结果 代码: #include<iostream> ...

  3. HDU 4406 最大费用最大流

    题意:现有m门课程需要复习,已知每门课程的基础分和学分,共有n天可以复习,每天分为k个时间段,每个时间段可以复习一门课程,并使这门课程的分数加一,问在不挂科的情况下最高的绩点. 思路:(没做过费用流的 ...

  4. hdu 4406 费用流

    这题问题就是当前时刻究竟选择哪门课程,易知选择是和分数有关的,而且是一个变化的权值,所以能够用拆点的方式,把从基础分到100分都拆成点.但若这样拆点的话,跑费用流时就必须保证顺序.这样就麻烦了..观察 ...

  5. [GodLove]Wine93 Tarining Round #6

    比赛链接: http://vjudge.net/contest/view.action?cid=47642#overview 题目来源: 2012 ACM/ICPC Asia Regional Jin ...

  6. hdu 4968 最大最小gpa

    http://acm.hdu.edu.cn/showproblem.php?pid=4968 给定平均分和科目数量,要求保证及格的前提下,求平均绩点的最大值和最小值. dp[i][j]表示i个科目,总 ...

  7. HDU 4968 Improving the GPA(dp)

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

  8. Improving the GPA 分类: 贪心 HDU 比赛 2015-08-08 16:12 11人阅读 评论(0) 收藏

    Improving the GPA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...

  9. HDU 4968 Improving the GPA

    Improving the GPA Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

随机推荐

  1. Hadoop_MapReduce中Mapper类和Reduce类

    在权威指南中,有个关于处理温度的MapReduce类,具体如下: 第一部分:Map public class MaxTemperatureMapper extends MapReduceBase im ...

  2. 紫书 习题 11-16 UVa 1669(树形dp)

    想了很久, 以为是网络流最大流, 后来建模建不出来, 无奈. 后来看了 https://blog.csdn.net/hao_zong_yin/article/details/79441180 感觉思路 ...

  3. Json学习总结(2)——Java 下的 JSON库性能比较:JSON.simple vs. GSON vs. Jackson vs. JSONP

    JSON已经成为当前服务器与WEB应用之间数据传输的公认标准,不过正如许多我们所习以为常的事情一样,你会觉得这是理所当然的便不再深入思考了.我们很少会去想用到的这些JSON库到底有什么不同,但事实上它 ...

  4. javascript jquery 推断对象为空的方式

    java中存在非常多空指针的问题,须要常常做预防和推断,如若不然,控制台出现恼人的异常,让人信心备受打击,早期敲代码的时候没有经验,不能依据异常信息找到问题的根源,唯一做的事情就是祈祷,千万别出现什么 ...

  5. 在java项目中怎样利用Dom4j解析XML文件获取数据

    在曾经的学习.net时常常会遇到利用配置文件来解决项目中一些须要常常变换的数据.比方数据库的连接字符串儿等.这个时候在读取配置文件的时候.我们一般会用到一个雷configuration,通过这个类来进 ...

  6. mysql-过程与函数

    一.过程与函数简介 过程与函数是命名的PL/SQL块(也是用户的方案对象),被编译后存储在数据库中,以备执行.因此,其他PL/SQL块可以按名称来使用他们.所以可以将商业逻辑.企业规划写成函数或过程保 ...

  7. android 自己定义标签的使用,实现扁平化UI设计

    2014年8月6日11:06:44 android对自己定义标签的使用.实现扁平化UI设计: 1.attrs.xml文件里自己定义标签 如: <?xml version="1.0&qu ...

  8. Android开发:getViewById返回null的原因定位

    近期在研究开发一些基于Android的App,遇到了一些问题.当中一个比較关键的是在Activity中的onCreate()方法中获取Button对象.代码大概例如以下: private Button ...

  9. 动态语言切换(续)-designer中的retranslateUi(带源码)

    本站所有文章由本站和原作者保留一切权力,仅在保留本版权信息.原文链接.原文作者的情况下允许转载,转载请勿删改原文内容, 并不得用于商业用途. 谢谢合作.原文链接:动态语言切换(续)-designer中 ...

  10. h5登录

    <!DOCTYPE html> <html lang="zh-cn"> <head> <meta http-equiv="Con ...