ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

阿里巴巴20220422笔试编程题

2022-04-22 13:03:48  阅读:126  来源: 互联网

标签:笔试 2022 int 31 编程 样例 && 20220422 dp


备忘录

添加记录
输入1 x y z s, 代表x年y月z日添加了一条记录s
2.查询信息数量
输入2 x y z, 代表查询x年y月z日的信息数量
3.查询信息日期
输入3 s, 查询信息s的所在日期
日期可能非法,x[2022, 9999];
注意1, 日期非法输出"error", s已存在输出"existed", 添加成功输出"done"
注意2, 日期非法输出"error", 输出整数
注意3, 信息不存在输出"not existed", 否则输出日期,注意格式2022/04/22
样例输入
6
1 2022 3 32 ranko
1 2022 3 31 ranko
1 2022 1 1 ranko
2 2022 3 31
3 ranko
3 kotori
样例输出
error
done
existed
1
2022/03/31
not existed

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int n, x, y, z, op;
map<string, vector<int> > mark; //标记信息日期
map<string, int> vis;
map<vector<int>, int> number; // 统计某天信息个数
vector<int> v;
string s;
int dir[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool judge(int x){
	if((x % 400) == 0 || ((x % 4) == 0 && ( x % 100) != 0)) return true;
	return false;
}
int f(int x, int y, int z){
	if(y == 2 && z == 29 && judge(x)) return true;
	if(x < 2022 || x > 9999) return false;
	if(y < 1 || y > 13) return false;
	if(z < 1 || z > dir[y]) return false;
	return true;
}
void add(int x, int y, int z){
	v.clear(); v.push_back(x);
	v.push_back(y); v.push_back(z);
}
int main(){
	cin >> n;
	while(n--){
		cin >> op;
		if(op == 1){
			cin >> x >> y >> z >> s;
			if(!f(x, y, z)) {
				cout << "error" << endl;
			}else if(vis[s] == 1){
				cout << "existed" << endl;
			}else{
				vis[s] = 1;
				add(x, y, z);
				number[v] ++; mark[s] = v;
				cout << "done" << endl;
			}
		}else if(op == 2){
			cin >> x >> y >> z;
			if(!f(x, y, z)){
				cout << "error" << endl;
			}else{
				add(x, y, z);
				cout << number[v] << endl;
			}
		}else{
			cin >> s;
			if(vis[s] == 0){
				cout << "not existed" << endl;
			}else{
				v = mark[s];
				cout << v[0] << '/';
				v[1] < 10 ? cout << '0' << v[1] << '/' : cout << v[1] << '/';
				v[2] < 10 ? cout << '0' << v[2] << endl : cout << v[2] << endl;
			}
		}
	}
    return 0;
}

严格上升子序列

给定一个数组,删除连续的一个子数组,使得剩余部分严格递增,最少需要删掉几个数
输入样例
6
1 3 1 2 4 5
输出样例
2
输入样例
6
1 2 3 3 4 5
输出样例
1
输入样例
7
4 5 2 3 4 1 2
输出样例
5
预处理前后缀,暴力更新

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    int n, ans;
    cin >> n;
    vector<vector<int> > dp(3, vector<int>(n + 1, 0));
    dp[1][0] = dp[2][n - 1] = 1;
    ans = n - 1;
    for(int i = 0; i < n; i++){
        cin >> dp[0][i];
        if(i == 0) continue;
        if(i && dp[0][i] > dp[0][i - 1] && dp[1][i - 1] != 0) dp[1][i] = dp[1][i - 1] + 1;
        else dp[1][i] = 0;
        ans = min(ans, n - dp[1][i]);
    }
    for(int i = n - 2; i >= 0; i--){
        if(dp[0][i] < dp[0][i + 1] && dp[2][i + 1] != 0) dp[2][i] = dp[2][i + 1] + 1;
        else dp[2][i] = 0;
        ans = min(ans, n - dp[2][i]);
    }
    int l = -1, r = 0;
    while(r < n && dp[2][r] == 0) r++;
    while(l < n){
        l++;
        if(dp[1][l] == 0) continue;
        while(r < n && dp[0][l] >= dp[0][r]) r++;
        if(r < n && dp[0][l] < dp[0][r]) ans = min(ans, n - dp[1][l] - dp[2][r]);
    }
    cout << ans << endl;
    return 0;
}

标签:笔试,2022,int,31,编程,样例,&&,20220422,dp
来源: https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/16178385.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有