美团4-29实习-校招笔试题 只AC了三道题
美团4-29 10:00的笔试题一共4道代码题+1道专项题,本弱鸡在英国有时差,定了个闹钟凌晨2点多起来。头昏脑胀第一题写了将近1个小时。。。最终只写了代码题前3题(100%),而且写的很乱,大家感兴趣的可以将就着看下(题目只放了前三题)。
踢皮球
时间限制: 1000MS内存限制: 65536KB题目描述:某大学最近正在进行选课。对于学校开设的部分课程,只允许大一至大四中部分年级和部分学院的学生在选课系统中自行选课,年级或学院不符合要求的学生只能通过教务科代为选课。但是不幸的是,各个学院教务科只能帮自己学院的学生选择自己学院开设的课程。
此时出现的一个问题是,A学院的小美想请教务处代选B学院开设的课程时,A学院的教务科没有权限将学生添加到B学院开设的课程,因此让小美去找B学院的教务科,B学院的教务科没有权限调取就读A学院学生的个人信息,因此让小美去找A学院的教务科。此时我们说小美被踢皮球了。
为了方便处理,可以认为一共有n门课程,编号为1~n;m个学院,编号为1~m 。给出n门可选课程及其开课学院、允许在系统选课的年级和专业,进行q次查询,每次查询给出学生所属学院和待选课程。若可以自行在选课,输出"Help yourself"(不包括引号,下同);否则若可以由教务处成功代选,输出"Ask for help";否则说明该学生会被踢皮球,输出"Impossible"。
注意:只有年级和学院都不被限制的学生可以自行选课。
输入描述
第一行输入3个正整数n,m,q
第二行输入n个正整数si,表示编号为i的课程的开课学院为si;
接下来4行输入一个4×n的01矩阵f,fij=0表示不允许i年级的学生自行选j课程,fij=1则表示允许;
接下来m行输入一个m×n的01矩阵g,gij=0表示不允许i学院的学生自行选j课程,gij=1则表示允许;
接下来q行,每行输入3个正整数a,b,c ,表示学生所属学院、年级、待选课程。
输出描述
输出共q行,每行一个字符串表示对应查询的结果。
样例输入
5 2 4
1 2 2 1 1
1 0 0 0 0
0 0 1 1 1
0 0 0 0 1
0 0 1 0 1
1 0 0 1 1
0 1 0 0 0
2 2 3
2 3 2
2 3 1
1 2 4
样例输出
Ask for help
Ask for help
Impossible
Help yourself
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, q;
int a, b, c;
int s[1005];
int f[4][1005];
int g[1005][1005];
scanf("%d %d %d", &n, &m, &q);
for (int i = 0; i < n; i++) {
scanf("%d", &s[i]);
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &f[i][j]);
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &g[i][j]);
}
}
for (int i = 0; i < q; i++) {
scanf("%d %d %d", &a, &b, &c);
if (f[b - 1][c - 1] == 1 && g[a - 1][c - 1] == 1) {
cout << "Help yourself" << endl;
} else if (a == s[c - 1]) {
cout << "Ask for help" << endl;
} else {
cout << "Impossible" << endl;
}
}
}
限行
时间限制: 3000MS
内存限制: 589824KB
题目描述:
在小美的城市,为了保证交通顺畅,在周一至周日的每一天都会对部分车辆限行。例如周一不允许车牌号最后一个数字为0、1、2的车辆出行,周二不允许车牌号最后一个数字为3、4、5的车辆出行……然而小美是个有钱人,因此她决定多买几辆车,以保证她每天都至少有一辆车可以出行。假设小美可以任意选择车牌号的最后一位数字,请你告诉她至少需要买几辆车?如果小美无法达到目标,输出-1即可。
输入描述
输入共7行,表示周一至周日的限行情况。
每行第一个数字ci表示当天限行数字个数,随后输入ci 个互不相同的数字aij,表示限行数字。
对于所有的数据,0≤ci≤10, 0≤aij≤9。
输出描述
一行,输出一个整数,表示小美需要的最少车辆数或小美不能保证每天都至少有一辆车可以出行。
样例输入
8 0 1 2 3 4 5 6 7
8 1 2 3 4 5 6 7 8
8 2 3 4 5 6 7 8 9
8 0 1 2 3 4 5 8 9
8 0 1 2 3 6 7 8 9
8 0 1 4 5 6 7 8 9
8 2 3 4 5 6 7 8 9
样例输出
5
提示
一种可能的方案是,选购最后车牌一位数字分别为0,2,4,6,8的5辆车,此时每天都有车辆可以出行。
import java.util.*;
public class Main {
private static int ans = Integer.MAX_VALUE;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int [][] days = new int[10][15];
Map<Integer, Boolean> hashMap = new HashMap(){{
put(0, true);put(1, true);put(2, true);put(3, true);put(4, true);put(5, true);put(6, true);put(7, true);put(8, true);put(9, true);
}};
List<List<Integer>> list = new ArrayList<>();
for(int day = 0; day < 7; day++) {
int n = scanner.nextInt();
for(int i = 0; i < n; i++) {
days[day][i] = scanner.nextInt();
hashMap.put(days[day][i], false);
}
List<Integer> part = new ArrayList<>();
for(Map.Entry<Integer, Boolean> entry : hashMap.entrySet()) {
if(entry.getValue() == true) {
part.add(entry.getKey());
}
}
list.add(part);
hashMap = new HashMap(){{
put(0, true);put(1, true);put(2, true);put(3, true);put(4, true);put(5, true);put(6, true);put(7, true);put(8, true);put(9, true);
}};
}
dfs(list, 0, new HashSet<Integer>());
if(ans == Integer.MAX_VALUE) {
ans = -1;
}
System.out.println(ans);
}
public static void dfs(List<List<Integer>> list, int index, Set<Integer> sets) {
if(index == 7) {
ans = Math.min(ans, sets.size());
return;
}
List<Integer> integers = list.get(index);
for(int i = 0; i < integers.size(); i++) {
if(!sets.contains(integers.get(i))) {
sets.add(integers.get(i));
dfs(list, index + 1, sets);
sets.remove(integers.get(i));
} else {
dfs(list, index + 1, sets);
}
}
}
}
吃火锅
时间限制: 1000MS
内存限制: 65536KB
题目描述:
小美和她的朋友们共n人决定挑战超辣火锅,以决出最能吃辣的人。他们顺时针围成一圈,假设标号为1到n。从1号开始,每一次从当前的人顺时针数k个,然后这个人吃一口超辣火锅。第i个人对辣椒的耐受值为ai, 意味着当他吃了ai口火锅后将因无法忍受而离席(每次数k个人时,离席的人不算入其中,详见样例解释)。请你依次输出离席的人的编号。
输入描述
第一行读入用空格隔开的两个正整数n,k 。
第二行读入用空格隔开的n个正整数ai 。
对于所有的数据:
输出描述
一行输出用空格隔开的n个正整数,表示按时间从早到晚离席的人的编号。
样例输入
5 2
1 4 2 9 4
样例输出
1 3 5 4 2
#include <bits/stdc++.h>
using namespace std;
struct {
int idx;
int val;
} p[1005];
int main() {
int n, k;
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &p[i].val);
p[i].idx = i + 1;
}
int pos = 0;
while (true) {
p[pos].val -= 1;
if (p[pos].val == 0) {
int markX = p[pos].idx;
for (int i = pos; i < n - 1; i++) {
p[i] = p[i + 1];
}
n -= 1;
//
// printf("pos = %d\n", pos);
if (n != 0)
pos = (pos + n - 1) % n;
if (n == 0) {
printf("%d\n", markX);
break;
} else {
printf("%d ", markX);
}
}
pos = (pos + k) % n;
}
}
#笔试##面经##美团##校招##实习#
腾讯公司福利 1159人发布
