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

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
Output
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
#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的更多相关文章
- hdu 4802 GPA 水题
GPA Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4802 Des ...
- HDU - 4802 - GPA (水题)
题意: 计算GPA,输入一个数字和一个字符串,用 数字×字符串对应的数值 思路: 用map对应数值,要注意的是字符串为P或者N的时候,不计入结果 代码: #include<iostream> ...
- HDU 4406 最大费用最大流
题意:现有m门课程需要复习,已知每门课程的基础分和学分,共有n天可以复习,每天分为k个时间段,每个时间段可以复习一门课程,并使这门课程的分数加一,问在不挂科的情况下最高的绩点. 思路:(没做过费用流的 ...
- hdu 4406 费用流
这题问题就是当前时刻究竟选择哪门课程,易知选择是和分数有关的,而且是一个变化的权值,所以能够用拆点的方式,把从基础分到100分都拆成点.但若这样拆点的话,跑费用流时就必须保证顺序.这样就麻烦了..观察 ...
- [GodLove]Wine93 Tarining Round #6
比赛链接: http://vjudge.net/contest/view.action?cid=47642#overview 题目来源: 2012 ACM/ICPC Asia Regional Jin ...
- hdu 4968 最大最小gpa
http://acm.hdu.edu.cn/showproblem.php?pid=4968 给定平均分和科目数量,要求保证及格的前提下,求平均绩点的最大值和最小值. dp[i][j]表示i个科目,总 ...
- HDU 4968 Improving the GPA(dp)
HDU 4968 Improving the GPA 题目链接 dp.最大最小分别dp一次,dp[i][j]表示第i个人,还有j分的情况,分数能够减掉60最为状态 代码: #include <c ...
- 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) ...
- HDU 4968 Improving the GPA
Improving the GPA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
随机推荐
- 使用rman恢复数据小结
恢复前提有数据备份 以 alter database open resetlogs 开机以后多要做一次全备(以前的备份失效了) 恢复参数文件: restore spfile from '/home/o ...
- CSS3-----transform 转换
transforn 可以转换元素,其中主要属性有:rotate() / skew() / scale() / translate()以下4种. transform:rotate():旋转:其中“de ...
- ActiveMQ学习笔记(17)----Message高级特性(一)
1. Messaage Properties ActiveMQ支持很多消息属性,具体可以参考 http://activemq.apache.org/activemq-message-propertie ...
- SpringCloud学习笔记(5)----Spring Cloud Netflix之Eureka的服务认证和集群
1. Eureka服务认证 1. 引入依赖 <dependency> <groupId>org.springframework.boot</groupId> < ...
- C语言基础 (2) linux命令
01.课程回顾 链接 ln 1.txt aaa.txt 硬链接 (两个相互独立 删除一个另外一个还在) ln -s 1.txt aaa.txt软连接 (后面的是快捷方式) 硬链接只能是文件,软连接可 ...
- 【转载】spring boot 链接 虚拟机(Linux) redis
原文:https://www.imooc.com/article/43279?block_id=tuijian_wz 前提是你已经安装redis且支持远程连接,redis的安装这里不再赘述,有需要的可 ...
- Mac安装软件时,提示文件已损坏,需要移动到废纸篓的解决方法
1.修改系统偏好设置,安全性与隐私-->将“允许从以下位置下载的应用” ☑️任何来源. 2. mac10.12以上的系统一般没有“任何来源”这个选项,需打开terminnal终端,输入 sudo ...
- code vs 1245 最小的N个和
1245 最小的N个和 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 有两个长度为 N 的序列 A ...
- Android数据分批载入-滑动究竟部自己主动载入列表
Android数据分批载入-滑动究竟部自己主动载入列表 2014年5月9日 摘自:<Android高级开发实战-ui.ndk与安全> 本博文介绍怎样进行数据分批载入,在应用开发其中会常常使 ...
- USACO Ski Course Design解析和C语言实现
题目大意: John农场有N(1=<N<=1000)小丘陵(山),它们高度的范围从0 到 100 但仅仅有当最大的高度差不大于17时.才干够避税.John对它们进行改造,从高的丘陵上取土放 ...