zoukankan      html  css  js  c++  java
  • 11.5 校内模拟赛解题报告

    T1

    将字符串按长度排序,然后对字符串进行压缩,从 (a)(z) 排,排满了之后从 (aa)(zz) 排。

    /*
    Date:
    Source:
    Knowledge:
    */
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <map>
    #include <algorithm>
    #define orz cout << "AK IOI" << "
    "
    
    using namespace std;
    const int maxn = 1010;
    
    int read()
    {
    	int x = 0, f = 1; char ch = getchar();
    	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    	while(ch <= '9' && ch >= '0') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
    	return x * f;
    }
    void print(int X)
    {
    	if(X < 0) X = ~(X - 1), putchar('-');
    	if(X > 9) print(X / 10);
    	putchar(X % 10 ^ '0');
    }
    int Max(int a, int b){
    	return a > b ? a : b;
    }
    int Min(int a, int b){
    	return a < b ? a : b;
    }
    int n, num[maxn];
    string s[maxn];
    map<string, string> mp;
    map<int, string> pos;
    bool cmp(string a, string b)
    {
    	int len1 = a.length(), len2 = b.length();
    	return len1 < len2;
    }
    char tmp[maxn];
    void get_ans(int now)
    {
    	int js1 = 0, pos = now, js = 0;
    	while(now) num[++js] = now % 26, now /= 26;
    	for(int i = js; i >= 1; i--) tmp[js1++] = 'a' + num[i];
    	mp[s[pos]] = tmp;
    }
    int main()
    {
    	
    	n = read();
    	for(int i = 1; i <= n; i++)
    	{
    		cin >> s[i];
    		pos[i] = s[i];
    	}
    	sort(s + 1, s + n + 1, cmp);
    	int tot = unique(s + 1, s + n + 1) - s - 1;
    	for(int i = 1; i <= tot; i++) get_ans(i);
    	for(int i = 1; i <= n; i++) cout << mp[pos[i]], puts(" ");
    	fclose(stdin);
    	fclose(stdout);
    	return 0;
    }
    

    T2

    用并查集判是否有多余的边,再判断每个点的初度为 (1),有 (90) 分。说实话不知道它为啥不对,跟 AC 代码拍了很久也没拍出啥来。

    n = read();
    	for(int i = 1; i <= n; i++) fa[i] = i;
    	for(int i = 1; i <= n; i++)
    	{
    		int u = read(), v = read(), fu = find(u), fv = find(v);
    		if(in[v] != 0) {printf("%d", i); return 0;}
    		in[v]++;
    		if(fu == fv) {printf("%d", i); return 0;}
    		else fa[fv] = fu;
    	}
    

    正解:
    分类进行讨论。
    无环:
    找到入度 > 1 的点,把连向它的边编号最大的一个边删掉。
    有环:
    没有入度为 0 的点,就从环上找一个编号最大的边的删掉,
    如果有入度为 0 的点,就找出环上入度为 2 的点,并把连向该点的一条在环上的边删掉。
    找环的时候用 tarjan。

    /*
    Date:2021.11.5 
    Source:模拟赛 
    Knowledge: tarjan判环 
    */
    #include <iostream>
    #include <cstdio>
    #include <map>
    #include <stack>
    #define orz cout << "AK IOI" << "
    "
    
    using namespace std;
    const int maxn = 1e5 + 10;
    
    int read()
    {
    	int x = 0, f = 1; char ch = getchar();
    	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    	while(ch <= '9' && ch >= '0') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
    	return x * f;
    }
    void print(int X)
    {
    	if(X < 0) X = ~(X - 1), putchar('-');
    	if(X > 9) print(X / 10);
    	putchar(X % 10 ^ '0');
    }
    int Max(int a, int b){
    	return a > b ? a : b;
    }
    int Min(int a, int b){
    	return a < b ? a : b;
    }
    int n, in[maxn], val[maxn], from[maxn], to[maxn], dis[maxn], siz[maxn];
    struct node{
    	int u, v, nxt;
    }e[maxn << 1];
    int js, head[maxn];
    void add(int u, int v)
    {
    	e[++js] = (node){u, v, head[u]};
    	head[u] = js;
    }
    int tot, dfn[maxn], low[maxn], vis[maxn];
    stack <int> s;
    map <int, bool> link[maxn];
    void tarjan(int u) 
    {
    	s.push(u), vis[u] = 1;
    	low[u] = dfn[u] = ++tot;
    	for(int i = head[u]; i; i = e[i].nxt) 
    	{
    		int v = e[i].v;
    		if(!dfn[v]) 
    		{
    			tarjan(v);
    			low[u] = min(low[u], low[v]);
    		} 
    		else if(vis[v]) low[u] = min(low[u], dfn[v]);
    	}
    	int k, lst = u;
    	if(low[u] == dfn[u]) 
    	{
    		do{
    			k = s.top(), vis[k] = 0;
    			s.pop();
    			link[k][lst] = 1;
    			lst = k;
    			if(k == u) break;
    			dis[u] = max(dis[u], dis[k]);
    			siz[u]++;
    		}while(1);
    	}
    }
    int flag, id, tag;
    int main() {
    	//freopen("remove.in", "r", stdin);
    	//freopen("remove.out", "w", stdout);
    	n = read();
    	for(int i = 1; i <= n; i++) 
    	{
    		int u = read(), v = read();
    		val[v] = max(val[v], i);
    		from[i] = u, to[i] = v;
    		in[v]++, dis[v] = i;
    		add(u, v);
    		siz[i] = 1;
    	}
    	for(int i = 1; i <= n; i++) if(!dfn[i]) tarjan(i);
    	for(int i = 1; i <= n; i++) 
    	{
    		if(!in[i]) flag = 1;
    		if(in[i] == 2) id = i;
    	}
    	for(int i = 1; i <= n; i++) if(siz[i] == 1) tag++;
    	if(tag == n) {print(val[id]); return 0;}
    	if(flag) 
    	{
    		for(int i = n; i >= 1; i--) 
    		{
    			if(link[from[i]][to[i]] && to[i] == id) 
    			{
    				print(i);
    				return 0;
    			}
    		}
    	}
    	for(int i = 1; i <= n; i++) 
    		if(siz[i] > 1) {print(dis[i]); return 0;}
    	return 0;
    }
    /*
    	n = read();
    	for(int i = 1; i <= n; i++) fa[i] = i;
    	for(int i = 1; i <= n; i++)
    	{
    		int u = read(), v = read(), fu = find(u), fv = find(v);
    		if(in[v] != 0) {printf("%d", i); return 0;}
    		in[v]++;
    		if(fu == fv) {printf("%d", i); return 0;}
    		else fa[fv] = fu;
    	}
    */
    

    T3

    直接 DP, (f[i][j]) 表示甲剩的水量为 (i), 已剩的水量为 (j) 的概率。
    对于 (k = 1) 的部分分,打个表会发现,当 n 很大,并且 k=1 的时候,输出都是 1 。
    有个结论 (Ans(n,k) = Ans(frac{n - 1} K + 1, 1))。(向上取整)

    后面的情况都可以转换到 (k=1) 的情况。

    /*
    Date:
    Source:
    Knowledge:
    */
    #include <iostream>
    #include <cstdio>
    #define orz cout << "AK IOI" << "
    "
    
    using namespace std;
    const int maxn = 1e9 + 10;
    
    int read()
    {
    	int x = 0, f = 1; char ch = getchar();
    	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    	while(ch <= '9' && ch >= '0') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
    	return x * f;
    }
    void print(int X)
    {
    	if(X < 0) X = ~(X - 1), putchar('-');
    	if(X > 9) print(X / 10);
    	putchar(X % 10 ^ '0');
    }
    int Max(int a, int b){
    	return a > b ? a : b;
    }
    int Min(int a, int b){
    	return a < b ? a : b;
    }
    int n, K;
    double ans, f[1010][1010];
    
    int main()
    {
    	//freopen("tea.in", "r", stdin);
    	//freopen("tea.out", "w", stdout);
    	n = read(), K = read();
    	n = (n - 1) / K + 1, K = 1; // 向上取整 
    	if(n >= 1000) {puts("1.000000"); return 0;}
    	f[n][n] = 1.0;
    	for(int i = n; i >= 1; i--) 
    	{
    	    for(int j = n; j >= 1; j--) 
    		{
    	        for(int k = 1; k <= 4; k++) 
    	            f[max(0, i - k * K)][max(0, j - (4 - k) * K)] += f[i][j] / 4.0;
            }
        }
        for(int i = 1; i <= n; i++) ans = ans + f[0][i];
        ans = ans + f[0][0] / 2.0;
        printf("%.6lf
    ", ans);
    	fclose(stdin);
    	fclose(stdout);
    	return 0;
    }
    
    
  • 相关阅读:
    python 计时累积超过24小时时继续往上累加
    linux 下获取文件最后几行
    unbuntu 安装python包提示E: Unable to locate package python-timeout
    python 计时器
    jquery中html()、text()、val()的区别
    DESC和 ACS
    jQuery自动截取文字长度,超过部分
    Spring MVC 注解
    注解笔记
    Spring Data JPA初使用 *****重要********
  • 原文地址:https://www.cnblogs.com/yangchengcheng/p/15514982.html
Copyright © 2011-2022 走看看