两数组找相同的元素-array
时间限制:C/C++语言 1000MS;其他语言 3000MS
内存限制:C/C++语言 65536KB;其他语言 589824KB
题目描述:
给两个整数(int)数组,输出相同的元素。
输入
给定两个整型数组[a1, a2, ...., am],[b1, b2, ..., bn]
输入格式如下,第一行给定第一个数组的大小m,接下来的m行为其数组元素a1 -- am,每行一个元素;第m+1行为第二个数组的大小n,接下来的n行为其数组元素b1 -- bn,也是每行一个元素。示例如下:
m
a1
a2

am
n
b1
b2

bn

输出
两个数组中相同的元素,以空格分隔在一行中显示,显示顺序为其在第二个数组中出现的顺序。

样例输入
5
11
15
9
12
3
4
11
3
9
7

样例输出
11 3 9

开始用cin cout然后一直超时 苦思好久= =智障日常

#include<bits/stdc++.h>
using namespace std;int main()
{freopen("in.txt", "r", stdin);int n, m;int x;bool first = true;set<int> a;scanf("%d", &n);for (int i = 0; i < n; ++i) scanf("%d", &x), a.insert(x);scanf("%d", &m);for (int i = 0; i < m; ++i) {scanf("%d", &x);if (a.find(x) != a.end()) {if (first) first = false; else printf(" ");printf("%d", x);}}return 0;
}

View Code

DAU 统计
时间限制:C/C++语言 2000MS;其他语言 4000MS
内存限制:C/C++语言 32768KB;其他语言 557056KB
题目描述:
日活跃用户数 (DAU) 是衡量一个产品表现的重要指标。
需要编写程序,根据给定的某一天的 N 条访问记录,对当天的用户总数 M 进行统计。
每个用户可能访问多次。
为了方便,我们用数字 (uid) 唯一标识每个用户。
输入
每一行包含一个 uid,遇到 0 时认为输入结束。
输入共包含 N+1 行,可认为是无序的。
输出
一个数字:去重后 uid 的数量 M。

样例输入
12933
111111
59220
69433
59220
111111
0
样例输出
4

Hint
数据范围
0 < uid < 2^63
对于 30% 的数据,0 < N < 100,000, 0 < M < 100,000
对于 100% 的数据,0 < N < 1,000,000, 0 < M < 800,000

统计不重复的数字,利用set就可以了= =也是简单题

#include<bits/stdc++.h>
using namespace std;int main()
{std::ios::sync_with_stdio(false);long long x;set<long long> st;while (cin >> x) {if (x == 0) break;st.insert(x);}cout << st.size();return 0;
}

View Code

形式化算式
时间限制:C/C++语言 1000MS;其他语言 3000MS
内存限制:C/C++语言 65536KB;其他语言 589824KB
题目描述:
我们有如下形式化的数字*    ***   ***   * *   ***   ***   ***   ***   ***   ****      *     *   * *   *     *       *   * *   * *   * **    ***   ***   ***   ***   ***     *   ***   ***   * **    *       *     *     *   * *     *   * *     *   * **    ***   ***     *   ***   ***     *   ***   ***   ***
(* 下附图片供参考)分别表示 1 2 3 4 5 6 7 8 9 0
有如下形式化的符号:*        * *    *   *******  ***   *    **        * *  *     ****   ****
​(* 下附图片供参考)分别表示 + - * / = 小数点
输入
现在 将输入一个算式
输出
你要将该算式计算之后按照上述形式化的方式输出
各个数字和符号之间空两格
无法整除则保留两位小数样例输入
10 + 31
样例输出
*  ***       ***  *        * *  *
*  * *   *     *  *  ****  * *  *
*  * *  ***  ***  *        ***  *
*  * *   *     *  *  ****    *  *
*  ***       ***  *          *  *
​(* 下附图片供参考)Hint
样例输入2:
2 / 5
样例输出2:
***       ***        ***      * **    *  *    ****  * *      * *
***   *   ***        * *      ***
*    *      *  ****  * *  **    *
***       ***        ***  **    *
​(* 下附图片供参考)数据范围:
20%的数据 输入的数字和运算结果都是个位数
100%的数据保证 输入数字和答案都小于10000
100%的数据保证 输入数字不会出现小数
80%的数据保证 运算结果不会出现小数

第三题就是个大模拟,有点恶心就是了,写了半个多小时、、、、

#include<bits/stdc++.h>
using namespace std;string digit[10][5];
string opr[6][5];   // + - * / = .void init() {digit[0][0] = "***";digit[0][1] = "* *";digit[0][2] = "* *";digit[0][3] = "* *";digit[0][4] = "***";digit[1][0] = "*";digit[1][1] = "*";digit[1][2] = "*";digit[1][3] = "*";digit[1][4] = "*";digit[2][0] = "***";digit[2][1] = "  *";digit[2][2] = "***";digit[2][3] = "*  ";digit[2][4] = "***";digit[3][0] = "***";digit[3][1] = "  *";digit[3][2] = "***";digit[3][3] = "  *";digit[3][4] = "***";digit[4][0] = "* *";digit[4][1] = "* *";digit[4][2] = "***";digit[4][3] = "  *";digit[4][4] = "  *";digit[5][0] = "***";digit[5][1] = "*  ";digit[5][2] = "***";digit[5][3] = "  *";digit[5][4] = "***";digit[6][0] = "***";digit[6][1] = "*  ";digit[6][2] = "***";digit[6][3] = "* *";digit[6][4] = "***";digit[7][0] = "***";digit[7][1] = "  *";digit[7][2] = "  *";digit[7][3] = "  *";digit[7][4] = "  *";digit[8][0] = "***";digit[8][1] = "* *";digit[8][2] = "***";digit[8][3] = "* *";digit[8][4] = "***";digit[9][0] = "***";digit[9][1] = "* *";digit[9][2] = "***";digit[9][3] = "  *";digit[9][4] = "***";opr[0][0] = "   ";opr[0][1] = " * ";opr[0][2] = "***";opr[0][3] = " * ";opr[0][4] = "   ";opr[1][0] = "   ";opr[1][1] = "   ";opr[1][2] = "***";opr[1][3] = "   ";opr[1][4] = "   ";opr[2][0] = "   ";opr[2][1] = "* *";opr[2][2] = " * ";opr[2][3] = "* *";opr[2][4] = "   ";opr[3][0] = "   ";opr[3][1] = "  *";opr[3][2] = " * ";opr[3][3] = "*  ";opr[3][4] = "   ";opr[4][0] = "    ";opr[4][1] = "****";opr[4][2] = "    ";opr[4][3] = "****";opr[4][4] = "    ";opr[5][0] = "  ";opr[5][1] = "  ";opr[5][2] = "  ";opr[5][3] = "**";opr[5][4] = "**";}
//
//   *        * *    *   ****
//  ***  ***   *    *
//   *        * *  *     ****   **
//                              **//  *    ***   ***   * *   ***   ***   ***   ***   ***   ***
//  *      *     *   * *   *     *       *   * *   * *   * *
//  *    ***   ***   ***   ***   ***     *   ***   ***   * *
//  *    *       *     *     *   * *     *   * *     *   * *
//  *    ***   ***     *   ***   ***     *   ***   ***   ***void print_num(int x, int p) {   // 输出数字x的第p行int dig[10], idx = 0;do {dig[idx++] = x % 10;x /= 10;} while (x);//    for (int i = idx-1; i >= 0; --i) {
//        printf("%d", dig[i]);
//        if (i) printf(" ");
//    }
//    printf("\n");for (int i = idx-1; i >= 0; --i) {cout << digit[ dig[i] ][p];if (i) cout << "  ";}}void print_double(double x, int p) {   // 输出数字x的第p行int x1 = x;int x2 = ceil((x - x1) * 100);int dig[10], idx = 0;do {dig[idx++] = x1 % 10;x1 /= 10;} while (x1);for (int i = idx-1; i >= 0; --i) {cout << digit[ dig[i] ][p];cout << "  ";}cout << opr[5][p];cout << "  ";cout << digit[ x2 / 10 ][p];if (x2 % 10 != 0) {cout << "  ";cout << digit[ x2 % 10 ][p];}}int main()
{freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);int a, b, ans;char op;init();//print_num(120, 0);
scanf("%d%*c%c%*c%d", &a, &op, &b);//printf("%d %c %d\n", a, op, b);if (op == '+') {ans = a + b;for (int i = 0; i < 5; ++i) {print_num(a, i);printf(" ");printf(" ");cout << opr[0][i];printf(" ");printf(" ");print_num(b, i);printf(" ");printf(" ");cout << opr[4][i];printf(" ");printf(" ");print_num(ans, i);printf("\n");}} else if (op == '-') {ans = a - b; bool mi = false;if (ans < 0) mi = true, ans = -ans;for (int i = 0; i < 5; ++i) {print_num(a, i);printf(" ");printf(" ");cout << opr[1][i];printf(" ");printf(" ");print_num(b, i);printf(" ");printf(" ");cout << opr[4][i];printf(" ");printf(" ");if (mi) {cout << opr[1][i];printf(" ");printf(" ");}print_num(ans, i);printf("\n");}} else if (op == '*') {ans = a * b;for (int i = 0; i < 5; ++i) {print_num(a, i);printf(" ");printf(" ");cout << opr[2][i];printf(" ");printf(" ");print_num(b, i);printf(" ");printf(" ");cout << opr[4][i];printf(" ");printf(" ");print_num(ans, i);printf("\n");}} else {if (a % b == 0) {ans = a / b;for (int i = 0; i < 5; ++i) {print_num(a, i);printf(" ");printf(" ");cout << opr[3][i];printf(" ");printf(" ");print_num(b, i);printf(" ");printf(" ");cout << opr[4][i];printf(" ");printf(" ");print_num(ans, i);printf("\n");}} else {double fans = (double)a / b;//printf("%f", fans);for (int i = 0; i < 5; ++i) {print_num(a, i);printf(" ");printf(" ");cout << opr[3][i];printf(" ");printf(" ");print_num(b, i);printf(" ");printf(" ");cout << opr[4][i];printf(" ");printf(" ");print_double(fans, i);printf("\n");}}}return 0;
}

View Code

第四题:任务执行策略

呜呜呜好难啊,干瞪眼一个小时没思路,最后暴力一发还TLE没分= =

官方题解:

动态规划题。首先把三角形翻转一下,从底部来考虑每个元素。dp[i][j][k]表示考虑到第(i,j)个,当前选取了k个元素的最大值。前缀和维护最大值,就可以把转移优化到O(1)。

#include <algorithm>
#include <cassert>
#include <cstring>
#include <cstdio>const int N = 60;
const int M = 500 + 10;int dp[N][N][M], sum[N][N], a[N][N], n, m;int main() {assert(scanf("%d%d", &n, &m) == 2);assert(1 <= n && n <= 50);assert(1 <= m && m <= 500);for (int i = 1; i <= n; ++ i) {for (int j = 1; j <= i; ++ j) {assert(scanf("%d", &a[i][j]) == 1);assert(0 <= a[i][j] && a[i][j] <= 1000);}}for (int i = 1; i <= n; ++ i) {for (int j = 1; j <= i; ++ j) {sum[i][j] = sum[i][j - 1] + a[n - j + 1][i - j + 1];}}memset(dp, 200, sizeof(dp));for (int i = 0; i <= n; ++ i) {dp[i][0][0] = 0;}for (int i = 1; i <= n; ++ i) {for (int j = i; j >= 0; -- j) {for (int k = j; k <= m; ++ k) {dp[i][j][k] = std::max(dp[i][j + 1][k],dp[i - 1][std::max(0, j - 1)][k - j] + sum[i][j]);}}}printf("%d\n", dp[n][0][m]);return 0;
}

转载于:https://www.cnblogs.com/wenruo/p/6730544.html

今日头条2017校园招聘 春招4.18笔试相关推荐

  1. 今日头条2018校园招聘后端开发工程师(第二批)编程题 - 题解

    以前做过第三批的题目,今日头条2018校园招聘后端开发工程师(第三批)编程题 - 题解.这一场的题目偏技巧和算法,而第三批的题偏编码.这一场涉及的算法有二分查找.区间动态规划. 原题链接:点这儿. 第 ...

  2. 今日头条2018校园招聘后端开发工程师(第四批)编程题 - 题解

    做过第三批的题目,今日头条2018校园招聘后端开发工程师(第三批)编程题 - 题解和第二批的题目,今日头条2018校园招聘后端开发工程师(第二批)编程题 - 题解. 这一场题目还是挺好玩的,也挺有技巧 ...

  3. 索信达2021届校园招聘春招正式启动

    索信达2021届春招正式启动 "和喜欢的人一起工作" 如果你对前沿技术充满热情 致力于用技术改变未来 如果你对Data Science.AI感兴趣 愿意为数据变革做出贡献 那么 请 ...

  4. 今日头条2018校园招聘后端开发工程师(第二批)编程题 (Java版)

    本人技术小白一枚,文章只是记录个人的解题思路和过程 牛客网地址:原题链接 第一题:用户喜好 题目 为了不断优化推荐效果,今日头条每天要存储和处理海量数据.假设有这样一种场景:我们对用户按照它们的注册时 ...

  5. 今日头条2018校园招聘后端开发工程师(第三批)编程题 - 题解

    昨天做了下头条的后端开发工程师的编程题,这编码量大啊,两个小时,三个编程题,一个改错题,一个设计题,说实话,很考技术含量,而且编程题中有两个还特别考细心编码,如果两个小时能做三个题,确实非常不错了,写 ...

  6. 今日头条2018校园招聘第一题 ---POJ 2479

    第一次参加公司的招聘笔试,虽然只是抱着试试水的心态去参加的,可惜的是第一题就做错了..... 第一题,其实只是一个求最大子段和的变式题,不过笔试的时候也不知道怎么了,就是不知道思路,最后还写了一个错的 ...

  7. 今日头条2018校园招聘第一次笔试第二题“字符串拼接”题解(一维动态规划及递归解法)

    3.24晚的笔试,结束后题目看不到了,有人截图了,来源:https://www.jianshu.com/p/00d3fd1d9e23 最新更新:在leetcode 上有一道类似的题,区别在于第一种操作 ...

  8. 手串(暴力) - 今日头条2018校园招聘后端方向(9.10)

    时间限制:1秒 空间限制:65536K 题目描述 作为一个手串艺人,有金主向你订购了一条包含n个杂色串珠的手串--每个串珠要么无色,要么涂了若干种颜色.为了使手串的色彩看起来不那么单调,金主要求,手串 ...

  9. 今日头条2018校园招聘后端开发工程师 (第二批) 编程题 - 字母交换

    题目描述: [编码题]字符串S由小写字母构成,长度为n.定义一种操作,每次都可以挑选字符串中任意的两个相邻字母进行交换.询问在至多交换m次之后,字符串中最多有多少个连续的位置上的字母相同? 输入描述: ...

最新文章

  1. Python基本语法_基本数据类型_字典类型详解
  2. 前端(HTML/CSS/JS)-CSS编码规范
  3. 说说JSON和JSONP,也许你会豁然开朗,含jQuery用例
  4. MySQL为表添加外键约束
  5. 怎样写出健壮的CLI程序
  6. CSS 设计模式一 元素
  7. 【Android开发坑系列】之事件
  8. Asp.Net Core 工作单元 UnitOfWork UOW
  9. mysql用户权限表join_MyBatis映射利用mysql left join 解决N+1查询问题
  10. mysql事务-与pymyql的事务
  11. Java双十二活动代码_双十二直播脚本怎么写?戳我速领!
  12. android o 可下载字体,android自定义字体
  13. 梁宁:增长思维30讲脑图笔记
  14. 如何更改计算机用户账户和密码,怎么修改电脑用户账户
  15. NLP领域表达退化各向异性理解及对应策略总结
  16. HMI-PLC数据交换方式之一 区域指针
  17. 三次握手的过程、四次挥手、为什么要进行第三次握手、为什么要进行四次挥手
  18. Debug与Release版本的区别
  19. 程序实现蒙特卡洛算法计算PI值和积分
  20. 电路分析第二章 运算放大器

热门文章

  1. 电脑开机后黑屏解决办法
  2. Oracle数据库SQL查询结果去重——ROW_NUMBER() OVER
  3. 解决民生银行个人网银、财付通与IE9 x64不兼容的问题。
  4. 设计大赛看到撒娇的萨科达斯科
  5. 细数《Sizeable》中场景交互的梦境灵感
  6. 分布式链路追踪之Spring Cloud Sleuth夺命连环9问?
  7. 树莓派用VNC Viewer方式远程连接
  8. 记录第一次做炸鸡和炸薯条
  9. 去除qq右下角的新闻弹窗
  10. 老婆和老公搞笑对话(转载)