微软2016校园招聘在线笔试 [Recruitment]
描述
A company plans to recruit some new employees. There are N candidates (indexed from 1 to N) have taken the recruitment examination. After the examination, the well-estimated ability value as well as the expected salary per year of each candidate is collected by the Human Resource Department.
Now the company need to choose their new employees according to these data. To maximize the company's benefits, some principles should be followed:
1. There should be exactly X males and Y females.
2. The sum of salaries per year of the chosen candidates should not exceed the given budget B.
3. The sum of ability values of the chosen candidates should be maximum, without breaking the previous principles. Based on this, the sum of the salary per year should be minimum.
4. If there are multiple answers, choose the lexicographically smallest one. In other words, you should minimize the smallest index of the chosen candidates; If there are still multiple answers, then minimize the second smallest index; If still multiple answers, then minimize the third smallest one; ...
Your task is to help the company choose the new employees from those candidates.
输入
The first line contains four integers N, X, Y, and B, separated by a single space. The meanings of all these variables are showed in the description above. 1 <= N <= 100, 0 <= X <= N, 0 <= Y <= N, 1 <= X + Y <= N, 1 <= B <= 1000.
Then follows N lines. The i-th line contains the data of the i-th candidate: a character G, and two integers V and S, separated by a single space. G indicates the gender (either "M" for male, or "F" for female), V is the well-estimated ability value and S is the expected salary per year of this candidate. 1 <= V <= 10000, 0 <= S <= 10.
We assure that there is always at least one possible answer.
输出
On the first line, output the sum of ability values and the sum of salaries per year of the chosen candidates, separated by a single space.
On the second line, output the indexes of the chosen candidates in ascending order, separated by a single space.
- 样例输入
-
4 1 1 10
F 2 3
M 7 6
M 3 2
F 9 9 - 样例输出
-
9 9
1 2
思路,动态规划,男女分别求出在某个salary i,选择j个男/女的最小花费(转移方程比较简单就不写了,可以滚动数组求),最后枚举男的salary i和女的salary j 找最大值即可。剩下的就是细节,保证找出满足题目要求的最优解。应该不会超时。
代码没有提交验证,只是写了自己的思路。
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; #define inf 0x7fffffff #define read freopen("in.txt","r",stdin) #define N 111
#define B 1111
int dp[][][N][B];
int tr[][N][B];
int ss[N];
vector<int>v1,v2;
int main()
{
//read;
int n,x,y,b;
while (~scanf("%d%d%d%d\n",&n,&x,&y,&b))
{
memset(dp,-,sizeof(dp));
for (int i = ; i < ; ++i)
for (int j = ; j < ; ++j)
dp[i][j][][] = ;
char g;
int v,s;
int c1 = ,c2 = ;
for (int i = ; i <= n; ++i)
{
scanf("%c%d%d\n",&g,&v,&s);
ss[i] = s;
int c,f,r;
if (g == 'M')
{
c1++;
r = ;
c = c1;
}
else
{
c2++;
r = ;
c = c2;
}
f = c%;
for (int j = ; j <= c; ++j)
for (int k = ; k <= b; ++k)
{
dp[r][f][j][k] = dp[r][-f][j][k];
if (k >= s && ~dp[r][-f][j-][k-s] && dp[r][-f][j-][k-s] + v > dp[r][f][j][k])
{
dp[r][f][j][k] = dp[r][-f][j-][k-s] + v;
tr[r][j][k] = i;
}
}
}
int ans = ,cost = inf;
for (int i = ; i <= b; ++i)
for (int j = ; j <= b -i ; ++j)
{
if (dp[][c1%][x][i] == - || dp[][c2%][y][j] == -)
continue;
int ta =dp[][c1%][x][i] + dp[][c2%][y][j];
int tb = i + j;
if (ans < ta || (ans == ta && tb < cost))
{
ans = ta,cost = tb;
v1.clear();
int t1 = x, t2 = i;
while (tr[][t1][t2])
{
v1.push_back(tr[][t1][t2]);
t1--;
t2 -= ss[tr[][t1][t2]];
}
t1 = y, t2 = j;
while( tr[][t1][t2])
{
v1.push_back(tr[][t1][t2]);
t1--;
t2 -= ss[tr[][t1][t2]];
}
sort(v1.begin(),v1.end());
}
else if (ans == ta && cost == tb)
{
v2.clear();
int t1 = x, t2 = i;
while (tr[][t1][t2])
{
v2.push_back(tr[][t1][t2]);
t1--;
t2 -= ss[tr[][t1][t2]];
}
t1 = y, t2 = j;
while( tr[][t1][t2])
{
v2.push_back(tr[][t1][t2]);
t1--;
t2 -= ss[tr[][t1][t2]];
}
sort(v2.begin(),v2.end());
bool flag = false;
for (size_t i = ; i < v1.size(); ++i)
if (v1[i] > v2[i])
{
flag = true;
break;
}
if (flag)
{
v1.clear();
for (size_t i = ; i < v2.size(); ++i)
v1.push_back(v2[i]);
}
}
}
printf("%d %d\n",ans,cost);
for (size_t i = ; i < v1.size(); ++i)
{
if (i)
printf(" ");
printf("%d",v1[i]);
}
printf("\n"); }
return ;
}
另外求C题[Islands Travel]思路……,不会做……。以下:
描述
There are N islands on a planet whose coordinates are (X1, Y1), (X2, Y2), (X3, Y3) ..., (XN, YN). You starts at the 1st island (X1, Y1) and your destination is the n-th island (XN, YN). Travelling between i-th and j-th islands will cost you min{|Xi-Xj|, |Yi-Yj|} (|a| denotes the absolute value of a. min{a, b} denotes the smaller value between a and b) gold coins. You want to know what is the minimum cost to travel from the 1st island to the n-th island.
输入
Line 1: an integer N.
Line 2~N+1: each line contains two integers Xi and Yi.
For 40% data, N<=1000,0<=Xi,Yi<=100000.
For 100% data, N<=100000,0<=Xi,Yi<=1000000000.
输出
Output the minimum cost.
- 样例输入
-
3
2 2
1 7
7 6 - 样例输出
-
2
微软2016校园招聘在线笔试 [Recruitment]的更多相关文章
- 微软2016校园招聘在线笔试-Professor Q's Software
题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new softw ...
- 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if the number of different ch ...
- 微软2016校园招聘在线笔试 B Professor Q's Software [ 拓扑图dp ]
传送门 题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new s ...
- 题目3 : Spring Outing 微软2016校园招聘在线笔试第二场
题目3 : Spring Outing 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 You class are planning for a spring outin ...
- 微软2016校园招聘在线笔试之Magic Box
题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...
- hihocoder 1288 : Font Size (微软2016校园招聘4月在线笔试)
hihocoder 1288 笔试第一道..wa了好几次,也是无语..hihocoder错了不会告诉你失败的时候的测试集,这样有时候就很烦.. 遍历所有的字体,从min(w,h)开始逐渐变小开始遍历. ...
- 微软2016校园招聘4月在线笔试 A FontSize
题目链接:http://hihocoder.com/problemset/problem/1288 分析:题目中所求的是最大的FontSize(记为S),其应该满足P*[W/S]*[H/S] > ...
- 微软2016校园招聘4月在线笔试 ABC
题目链接:http://hihocoder.com/contest/mstest2016april1/problems 第一题:输入N,P,W,H,代表有N段文字,每段有ai个字,每行有⌊W/S⌋个字 ...
- 微软2016校园招聘4月在线笔试 hihocoder 1289 403 Forbidden
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描写叙述 Little Hi runs a web server. Sometimes he has to deny acces ...
随机推荐
- centos 简单用户管理
一.配置文件 /etc/passwd:存放用户信息,以“:”分割成7个部分 1.账号名称,用来对应UID: 2.早期密码存放位置,后来密码改存/etc/shadow中,以“x”代替: 3.UID,使用 ...
- heroku安装(win7x64)
Jdk安装:官网地址 http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html下载要安装的jdk版本. ...
- 编译时报错,找不到指定路径下的command,而路径是正确的。
使用的Fedora 18 64位的系统kernel,内核为3.6.10.按照要求使用yum install *** 安装各项工具. path路径使用提供的toolchain,各种路径也安装正确,却发现 ...
- Shader Wave
Shader Wave 一.原理 1. 采用 UV 坐标为原始数据,生成每一条波浪线. 2. 使用 Unity 的 Time.y 作为时间增量,动态变换波形. 二.操作步骤 1. 首先使用纹理坐标生成 ...
- 九度oj 题目1077:最大序列和
题目1077:最大序列和 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6435 解决:1931 题目描述: 给出一个整数序列S,其中有N个数,定义其中一个非空连续子序列T中所有数的和为T ...
- Java Class 利用classpath来获取源文件地址
利用classpath来获取源文件地址 @author ixenos 应用场景 Properties props = new Properties(); /** * . 代表java命令运行的目录 * ...
- android源码mm时的编译错误no ruler to make target `out/target/common/obj/JAVA_LIBRARIES/xxxx/javalib.jar', needed by `out/target/common/obj/APPS/xxxx_intermediates/classes-full-debug.jar'. Stop.
瞧见没有,就因为多了这一个反斜杠,浪费了一下午时间找问题,哭了~~~~
- javabean组件
javaBean组件引入: javaBean是使用java语言开发的一个可重用的组件,在Jsp开发中可以使用javaBean减少重复代码,使整个JSP代码的开发更简洁. 我们首先创建一个类叫做Stud ...
- POJ2586 Y2K Accounting Bug 解题报告
Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vi ...
- Ubuntu 16.04使用sudo apt-get -f install解决依赖时的注意事项(重点)
注意:在觉得软件依赖时,一般使用sudo apt-get -f install,但是也是非常危险的,尤其时一些软件需要删除某些依赖时,会导致原有安装的软件全部卸载.所以使用此命令时要时刻注意输出的这条 ...