• 阿里巴巴20220422笔试编程题


    备忘录

    添加记录
    输入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;
    }
    
    
  • 相关阅读:
    MVC的各个部分都有那些技术来实现?如何实现?
    spring入门学习
    动态 SQL 及安全性(Birt vs 润乾)
    报表的 SQL 植入风险及规避方法
    web 如何实现精准打印
    birt 报表与润乾报表对比
    ireport 与润乾报表对比
    银行存折套打续打功能 -- 报表如何记录上次打印的位置
    脚本中如何做填报数据校验
    鼠标悬停出现提示信息怎么做
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/16178385.html
Copyright © 2020-2023  润新知