微软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 ...
随机推荐
- 笔试算法题(44):简介 - 动态规划(Dynamic Programming)
议题:动态规划(Dynamic Programming) 分析: DP主要用于解决包含重叠子问题(Overlapping Subproblems)的最优化问题,其基本策略是将原问题分解为相似的子问题, ...
- 用SQLyog或Navicat远程连接数据库
以SQLyog为例(Navicat同理): 登录远程数据库服务器查看当前存在用户:即点击用户管理器(人像图标),查看用户. 1)如果某一用户 主机一栏中是"%",则表示本用户是开放 ...
- 初识 Spring 框架
初识 Spring 框架可以帮助我们构建规范的.优秀的应用程序,简化烦琐的编码过程. Spring 是一个非常著名的轻量级的企业级开源框架,Spring 的目标是使 Java EE 更易用并促进良好的 ...
- db2数据库,表相乘,直接扩大表数据
T1 表 SEQ表 想得到结果集为: 语句: SELECT * FROM (SELECT * FROM seq,t1) u LEFT JOIN t1 ON u.id=t1.id AND u.jjh=t ...
- jquery源码——noConflict实现
实现方式很简单:在初始化的时候,记录当前全局中jQuery和$两个变量的的值,用_jQuery和_$分别存放,调用noConflict方法时,使用_jQuery和_$分别恢复对应的值,并且返回jQue ...
- PS学习笔记(05)
PS学习笔记(09) [2]马赛克背景 找一张图片.然后新建图层,让前景色背景色恢复到默认的状态(黑.白) 在新建图层上填充黑色-->滤镜-->渲染->云彩 像素化-->马赛克 ...
- JDBC--JAVA数据库连接相关
JDBC API提供了以下接口和类: DriverManager: 这个类管理数据库驱动程序的列表.确定内容是否符合从Java应用程序使用的通信子协议正确的数据库驱动程序的连接请求.识别JDBC在一定 ...
- Leetcode 212.单词搜索II
单词搜索II 给定一个二维网格 board 和一个字典中的单词列表 words,找出所有同时在二维网格和字典中出现的单词. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中"相邻&q ...
- codevs4437 YJQ Arranges Sequences
题目描述 Description 神犇YJQ有两个长度均为n的数列A和B,并且A是一个单调不增的数列.他认为这两个数列的优美度为.有一天YJQ很无聊,他把Bi进行重新排列,得到了许多不同的优美度.他想 ...
- 【Java集合】Java中集合(List,Set,Map)
简介: 数组是大小固定的,并且同一个数组只能存放类型一样的数据(基本类型/引用类型),而JAVA集合可以存储和操作数目不固定的一组数据. 所有的JAVA集合都位于 java.util包中! JAVA集 ...