zoukankan      html  css  js  c++  java
  • QBXT模拟赛2

    QBXT模拟赛2

    总结

    期望得分:(100 + 40 + 0 = 140)
    实际得分:(0 + 0 + 0 = 0)

    鬼知道为什么我代码没有交上。。自测(10 + 50 + 0)……这是心态爆炸的一场考试
    (T1)敲了(3)个小时,写了(9kb),连样例都过不了,改了改过了样例迅速离开
    (T2)只会(40),但因为一个点的(a[i])很大,于是水过去了,变成了(50)
    (T3)连看都没看,(0)分滚粗

    我果是个彩笔

    思路&&代码

    T1

    模拟题, 一看这长长的题面,就知道是个简单题(fp嘛我做了三个小时不过样例能是简单题?)

    其实我觉得最难的不是别的,就是输入。。。这么一大堆字符串,还有(5)个位置,还是两个队,如何做到最简?

    其实这些可以化作一个整体,我们很容易想到要用结构体存储,但复杂的hapigou就是:结构体数组怎么开?

    我们可以开一个三维的(a)数组,存储两个队所有位置所有人的信息,(a[0])就表示(A)队,(a[1])就表示(B)队,(a[x][1-5])就表示(x)队五个位置的信息,(a[x][y][cnt])就表示(x)队第(y)个位置的第(cnt)名选手,这样不仅好理解,还方便了之后我们要用到的的排序

    再者,肯定要从实力由高到低的选,每次某个位置换的肯定是这个位置剩余的实力最强的人,所以我们就可以直接按照实力把每个位置的人排序,如果实力相同则编号较小的在前

    之后我们就要想怎么来选人了,要想让场上所有人的综合实力最大,我们要保证换下来的人与在场的人实力的差值最小,所以就可以在五个位置中找差值最小的位置来换,这样这道题就完美解决了

    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    const int A = 5e5 + 11;
    const int B = 1e6 + 11;
    const int INF = 1000;
    
    inline int read() {
    	char c = getchar(); int x = 0, f = 1;
    	for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    	for( ; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
    	return x * f;
    }
    
    struct node { char name[16]; int id, val; } a[2][6][A];
    int N, M, T, P, Q;
    int cnt[2][6], change[2][6];
    
    bool cmp(node a, node b) {
    	return a.val == b.val ? a.id < b.id : a.val > b.val;
    }
    
    inline int check(char s[4]) {
    	if(s[0] == 'p' && s[1] == 'g') return 1;
    	if(s[0] == 's' && s[1] == 'g') return 2;
    	if(s[0] == 's' && s[1] == 'f') return 3;
    	if(s[0] == 'p' && s[1] == 'f') return 4;
    	if(s[0] == 'c') return 5;
    }
    
    inline void add(int dui, char name[16], int pos, int id, int val) {
    	a[dui][pos][++cnt[dui][pos]].id = id;
    	strcpy(a[dui][pos][cnt[dui][pos]].name, name);
    	a[dui][pos][cnt[dui][pos]].val = val;
    }
    
    int main() {
    	N = read(), M = read(), T = read(), P = read(), Q = read();
    	char s[4], name[16]; int idd, val, dui;
    	for(int i = 1; i <= N + M; i++) {
    		dui = (i <= N ? 0 : 1);
    		scanf("%s %d %s %d", name, &idd, s, &val);
    		add(dui, name, check(s), idd, val);
    	}
    	for(int i = 1; i <= 5; i++) sort(a[0][i] + 1, a[0][i] + cnt[0][i] + 1, cmp), sort(a[1][i] + 1, a[1][i] + cnt[1][i] + 1, cmp);
    	for(int i = 1; i <= 5; i++) change[1][i] = 1, change[0][i] = 1;
    	int suma = 1, sumb = 1, team;
    	while(P * suma < T || Q * sumb < T) {
    		if(P * suma <= Q * sumb) team = 0, suma++; else team = 1, sumb++;
    		int minn = 10000000, po; node be, aft;
    		for(int i = 1; i <= 5; i++) {
    			int k = change[team][i], c = a[team][i][k].val - a[team][i][k + 1].val;
    			if(k == cnt[team][i]) continue;
    			if(c < minn || (c == minn && a[team][i][k + 1].id < aft.id)) minn = c, po = i, be = a[team][i][k], aft = a[team][i][k + 1];
    		}
    		change[team][po]++;
    		char dui = (team == 0 ? 'A' : 'B');
    		printf("Substitution by %c,No.%d %s is coming up to change No.%d %s.
    ", dui, aft.id, aft.name, be.id, be.name);
    	}
    	return 0;
    }
    
    

    T2

    这道题到现在我还是只会五十分,很容易想到是一个贪心的思路,我们直接用两个指针表示从左边右边拿,就能拿五十了

    满分的也在下面,还是不会。。菜死了

    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    const int A = 1e5 + 11;
    const int B = 1e6 + 11;
    const int INF = 0x3f3f3f3f;
    
    inline int read() {
    	char c = getchar(); int x = 0, f = 1;
    	for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    	for( ; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
    	return x * f;
    }
    
    int n, T, x[A], a[A];
    
    namespace sub {
    	int maxn = -INF;
    	inline void Main() {
    		for(int i = 1; i <= n; i++) {
    			int now = 0, ans = 0, l = i - 1, r = i + 1, one;
    			while(now <= T) {
    				if(l < 1 && r > n) break;
    				else if(l >= 1 && r <= n && x[i] - x[l] <= x[r] - x[i]) {
    					one = min((T - now) / ((x[i] - x[l]) * 2), a[l]);
    					now += (x[i] - x[l]) * 2 * one, ans += one;
    					if(one == a[l]) l--; else break;
    				} 
    				else if(l >= 1 && r <= n && x[i] - x[l] > x[r] - x[i]) {
    					one = min((T - now) / ((x[r] - x[i]) * 2), a[r]);
    					now += (x[r] - x[i]) * 2 * one, ans += one;
    					if(one == a[r]) r++; else break;
    				}
    				else if(l < 1 && r <= n) {
    					one = min((T - now) / ((x[r] - x[i]) * 2), a[r]);
    					now += (x[r] - x[i]) * 2 * one, ans += one;
    					if(one == a[r]) r++; else break;
    				}
    				else if(l >= 1 && r > n) {
    					one = min((T - now) / ((x[i] - x[l]) * 2), a[l]);
    					now += (x[i] - x[l]) * 2 * one, ans += one;
    					if(one == a[l]) l--; else break;
    				}
    			}
    			maxn = max(maxn, ans + a[i]);
    		}
    		cout << maxn << '
    ';
    		return;
    	}
    }
    
    int main() {
    	n = read(), T = read();
    	for(int i = 1; i <= n; i++) x[i] = read();
    	for(int i = 1; i <= n; i++) a[i] = read();
    	if(n <= 1000) return sub::Main(), 0;
    	
    	return 0;
    }
    
    
    #include<bits/stdc++.h>
    #define int long long
    using namespace std;
    
    const int N = 5e5 + 11;
    
    inline int read() {
    	char c = getchar(); int x = 0, f = 1;
    	for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    	for( ; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
    	return x * f;
    }
    
    int s[N], T;
    int x[N], a[N], n;
    
    bool check(int H) {
    	int nowh = 0, tim = 0;
    	int lc = 0, rc = 0, l = 1, r = n + 1;
    	for (int i = 1; i <= n; i++)
    		if (nowh + a[i] <= H) nowh += a[i], tim += (int)(x[i] - x[1]) * a[i];
    		else {r = i, rc = H - nowh, tim += (int)(x[i] - x[1]) * rc; break;}
    	if (tim <= T) return 1;
    	for (int i = 2; i <= n; i++) {
    		int suml = s[i - 1] - s[l - 1] - lc;
    		int sumr = s[r - 1] - s[i - 1] + rc;
    		tim += (x[i] - x[i - 1]) * (suml - sumr);
    		while (r <= n && x[i] - x[l] > x[r] - x[i]) {
    			int can = min(a[l] - lc, a[r] - rc);
    			tim += (x[r] - x[i] - x[i] + x[l]) * can;
    			lc += can, rc += can;
    			if (lc >= a[l]) ++l, lc = 0;
    			if (rc >= a[r]) ++r, rc = 0;
    		}
    		if (tim <= T) return 1;
    	}
    	return 0;
    }
    
    signed main() {
    	n = read(), T = read(); T /= 2;
    	for (int i = 1; i <= n; i++) x[i] = read();
    	for (int i = 1; i <= n; i++) a[i] = read();
    	for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
    	int l = 0, r = s[n], ans;
    	while (l <= r) {
    		int mid = (l + r) >> 1;
    		if (check(mid)) l = mid + 1, ans = mid;
    		else r = mid - 1;
    	}
    	cout << ans << '
    ';
    	return 0;
    }
    

    T3

    神仙字符串题,不会

    #include<bits/stdc++.h>
    #define N 500010
    #define ls (x << 1)
    #define rs (x << 1 | 1)
    using namespace std;
    typedef long long ll;
    struct intv{
    	int s, i;
    } a[N], b[N];
    int p[N], rc[N << 2], f[N], n, m, type, anss, sum[N << 2];
    ll ansf;
    char s[N];
    bool cmp(intv a, intv b) {
    	return a.s < b.s;
    }
    inline void updata(int x, int l, int r, int p) {
    	if (l == r) {
    		rc[x] = r, sum[x] = 1; return;
    	}
    	int mid = (l + r) >> 1;
    	if (p <= mid) updata(ls, l, mid, p);
    	else updata(rs, mid + 1, r, p);
    	sum[x] = sum[ls] + sum[rs];
    	rc[x] = (rc[rs] == -1 ? rc[ls] : rc[rs]);
    }
    inline intv query(int x, int l, int r, int xl, int xr) {
    	if (l == xl && r == xr) return (intv) {sum[x], rc[x]};
    	int mid = (l + r) >> 1;
    	if (xr <= mid) return query(ls, l, mid, xl, xr);
    	else if (xl > mid) return query(rs, mid + 1, r, xl, xr);
    	else {
    		intv ql = query(ls, l, mid, xl, mid), qr = query(rs, mid + 1, r, mid + 1, xr);
    		return (intv) {ql.s + qr.s, qr.i == -1 ? ql.i : qr.i};
    	}
    }
    int main() {
    	freopen("htstr.in", "r", stdin);
    	freopen("htstr.out", "w", stdout);
    	scanf("%s%d", s + 1, &type);
    	n = strlen(s + 1); s[0] = '#';
    	int mx = 0, id, now = 1;
    	for (int i = 1; i <= n; i++) {
    		if (mx >= i) p[i] = min(mx - i, p[2 * id - i]);
    		for (; s[i + p[i] + 1] == s[i - p[i]]; p[i]++);
    		if (p[i] + i < mx) id = i, mx = p[i] + i;
    	}
    	for (int i = 1; i <= n; i++) a[i] = (intv) {i - p[i], i};
    	sort(a + 1, a + n + 1, cmp);
    	for (int i = 1; i <= n << 2; i++) rc[i] = -1;
    	for (int i = 1; i <= n; i++) {
    		while (now <= n && a[now].s <= i) updata(1, 1, n, a[now].i), now++;
    		if (p[i] <= 1) continue;
    		intv qs = query(1, 1, n, i + 1, i + p[i] / 2);
    		ansf += (ll)qs.s;
    		if (qs.i != -1) b[++m] = (intv) {3 * i - 2 * qs.i + 1, 2 * qs.i - i};
    	}
    	if (type == 1) {printf("%I64d
    ", ansf + n); return 0;}
    	sort(b + 1, b + m + 1, cmp);
    	id = 1, mx = 0;
    	for (int r = 1; r <= n; r++) {
    		while (b[id].s <= r && id <= m) mx = max(mx, b[id].i), id++;
    		if (mx < r) ++anss, mx = r;
    		else r = mx, ++anss;
    	}
    	if (type == 2) printf("%d
    ", anss);
    	else printf("%I64d %d
    ", ansf + n, anss);
    	return 0;	
    }
    
  • 相关阅读:
    VueRouter-404错误配置
    VueRouter-组件复用
    VueRouter-动态路由
    vue-router基本使用
    Vue小作业--图书管理
    Vue的过滤器
    vue的生命周期
    vue中插槽
    vue自定义组件v-model
    Vue组件中自定义事件
  • 原文地址:https://www.cnblogs.com/loceaner/p/11797541.html
Copyright © 2011-2022 走看看