zoukankan      html  css  js  c++  java
  • 2018 计蒜之道 初赛 第二场

    签到完看到C没什么人过就溜乐。

    A.淘宝的推荐系统

    直接DP,时间复杂度$O(∑nd)$

    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define rep(i, a, b)	for (int i(a); i <= (b); ++i)
    #define dec(i, a, b)	for (int i(a); i >= (b); --i)
    #define MP		make_pair
    #define fi		first
    #define se		second
    
    
    typedef long long LL;
    
    const int N = 2e5 + 10;
    
    int f[N];
    int T;
    int ans;
    int n, d;
    
    
    int main(){
    
    	scanf("%d", &T);
    	while (T--){
    		scanf("%d%d", &n, &d);
    		memset(f, 0, sizeof f);
    
    		ans = 0;
    
    		rep(i, 1, n){
    			int x;
    			scanf("%d", &x);
    			int mx = 0;
    			rep(j, x - d, x + d){
    				if (j > 0) mx = max(mx, f[j]);
    			}
    
    			f[x] = max(f[x], mx + 1);
    			ans = max(ans, f[x]);
    		}
    
    		printf("%d
    ", ans);
    	}
    
    	return 0;
    }
    

     

    B.阿里巴巴的手机代理商(简单)

    map直接暴力。

    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define rep(i, a, b)	for (int i(a); i <= (b); ++i)
    #define dec(i, a, b)	for (int i(a); i >= (b); --i)
    #define MP		make_pair
    #define fi		first
    #define se		second
    
    
    typedef long long LL;
    
    map <string, int> mp;
    
    int T;
    int n;
    string op, ss, s;
    
    
    int main(){
    
    	std::ios::sync_with_stdio(false);
    
    	cin >> T;
    
    	while (T--){
    		cin >> n;
    		mp.clear();
    
    		rep(i, 1, n){
    			cin >> op;
    			if (op[0] == 'i'){
    				int y;
    				cin >> ss >> y;
    				mp[ss] += y;
    			}
    
    			else if (op[0] == 'q'){
    				cin >> ss;
    
    				int len = ss.length();
    
    				int ans = 0;
    
    				for (auto u : mp){
    					string s = u.fi;
    					int sz = s.length();
    					if (sz < len) continue;
    
    					int fg = 1;
    					int p = -1;
    					rep(i, sz - len, sz - 1){
    						++p;
    						if (s[i] != ss[p]){
    							fg = 0;
    							break;
    						}
    					}
    
    					if (fg) ans += u.se;
    				}
    				cout << ans << endl;	
    			}
    
    			else if (op[0] == 'd'){
    
    				cin >> ss;
    				if (mp[ss] == 0) cout << "Empty" << endl;
    				mp[ss] = 0;
    			}
    		}
    	}
    
    	return 0;
    }
    

    C.阿里巴巴的手机代理商(中等)

    看起来好像是个字典树上的模拟……待补

    D. 阿里巴巴的手机代理商(困难)

    留坑。听zlc1114说是……暴力?

  • 相关阅读:
    河北金力集团公文流转系统
    输出《Harry Potter and the Sorcerer's Stone》英文i的字母数量并排序
    四则运算自动出题系统
    输出《Harry Potter and the Sorcerer's Stone》文本中的前N个最长用的英文单词及其数量
    《程序员的修炼之道从小工到专家》第二章阅读有感
    异常处理动手动脑
    poj 1860
    poj 2182
    poj 2253
    poj 2001
  • 原文地址:https://www.cnblogs.com/cxhscst2/p/9034044.html
Copyright © 2011-2022 走看看