zoukankan      html  css  js  c++  java
  • 2020hdu多校第十场比赛及补题

    最后一场了,比赛前就希望这场不要是自闭场,然而前半场做的时候好自闭,不过后半场就很欢乐了 也许这就是ACM比赛的乐趣所在吧

    1004 Permutation Counting

    题意:a数列是全排列,b数列是由a数列决定的,b[i] = a[i+1] > a[i] ? 0 : 1,a数列的长度为n,b数列的长度为n-1,给定b数列,问有多少种a数列

    和队友一起想了两个多小时,还是不会,自闭了,我就去做1003去了, 然后队友就过了这题orz , 太强了

    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    const int MAXN = 5e3 + 7;
    const int MOD = 1e9 + 7;
    // const int INF = ;
    // const double eps = ;
    // const double PI = acos(-1);
    // const int DIRX[] = {};
    // const int DIRY[] = {};
    
    int T;
    int n;
    bool b[MAXN];
    int dp[MAXN][MAXN];
    int ans;
    
    int32_t main(void)
    {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cin >> T;
        while (T--)
        {
            memset(dp, 0, sizeof(dp));
            cin >> n;
            for (int i = 2; i <= n; ++i)
            {
                cin >> b[i];
            }
            dp[1][1] = 1;
            for (int i = 2; i <= n; ++i)
            {
                if (b[i] == 0)
                {
                    for (int j = 2; j <= i; ++j)
                    {
                        dp[i][j] = (dp[i - 1][j - 1] + dp[i][j - 1]) % MOD;
                    }
                }
                else
                {
                    for (int j = i; j >= 1; --j)
                    {
                        dp[i][j] = (dp[i - 1][j] + dp[i][j + 1]) % MOD;
                    }
                }
            }
            ans = 0;
            for (int i = 1; i <= n; ++i)
            {
                ans = (ans + dp[n][i]) % MOD;
            }
            ans %= MOD;
            cout << ans << endl;
        }
        return 0;
    }
    

      

    1003 Mine Sweeper

    读了下题,是阴间扫雷构造题

    都玩过扫雷吧,扫雷里有很多格子有数字,也有些格子有地雷,现在把所有数字加起来,记作S,给定S,让你构造一个扫雷图,若构造不出输出-1

    构造的扫雷图可以自定义行数和列数,不过行数要<=25,列数要<=25,S的范围是0~1000

    分析:

    • 先想办法构造使S尽量大,会发现S是可以超出1000很多的,所以可以断定是不存在输出-1的情况的
    • 可以想出很多种构造法,想出一种构造法,这种方法构造出来的S的范围是[L1,R1],再想出一种构造法,这种方法构造出来的S的范围是[L2, R2]...想,就硬想,直到[L1, R1],[L2, R2]...[Ln, Rn]能覆盖[0,1000]为止

    复制下面的代码,输入几组数据就知道我是怎样构造的了

    #include<iostream>
    #include<algorithm>
    using namespace std;
    char graph[30][30];
    int opx[8] = {-1,-1,-1,0,1,1,1,0};
    int opy[8] = {-1,0,1,1,1,0,-1,-1};
    void solve(int s){
    	//cout<<endl<<s<<endl;
    	int r, c, cs;
    	if(s==0){
    		cout<<1<<" "<<1<<endl<<"X"<<endl;	
    		return;
    	}
    	if(s < 25){
    		r = 1; c = s + 1;
    		cout << r << " " << c << endl;
    		for(int j = 1;j<=c;j++){
    			if(j % 2) cout<<"X";
    			else cout<<".";
    		}
    		cout<<endl;
    		return;
    	}
    	if(s <= 73){
    		r = 2;
    		cs = (s - 4) / 3;
    		if( cs * 3 + 4 == s){
    			c = cs + 2;
    			cout<<r<<" "<< c << endl;
    			for(int j = 1;j <= c;j++){
    				cout<<"X";
    			}
    			cout<<endl;
    			for(int j = 1;j <= c;j++){
    				cout<<".";
    			}
    			cout<<endl;
    			return;
    		}
    		cs++;
    		if( cs * 3 + 4 - 1 == s){
    			c = cs + 2;
    			cout << r << " " << c << endl;
    			for(int j = 1;j <= c;j++){
    				cout<<"X";
    			}
    			cout<<endl;
    			cout<<"X";
    			for(int j = 2;j <= c;j++) {
    				cout<<".";
    			}
    			cout<<endl;
    			return;
    		}
    		c = cs + 2;
    		cout << r << " " << c << endl;
    		for(int j = 1;j <= c;j++){
    			cout<<"X";
    		}
    		cout<<endl;
    		cout<<"X";
    		for(int j = 2;j <= c - 1;j++){
    			cout<<".";
    		}
    		cout<<"X";
    		cout<<endl;
    		return;
    	}
    	for(int i = 1;i <= 25;i++){
    		for(int j = 1;j <= 25;j++){
    			graph[i][j] = '.';
    		}
    	}	
    	int num = s / 8;
    	if(num <= 12) {
    		r = 3;
    		c = 2 * num + 1;
    	}
    	else{
    		int cs;
    		cs = num / 12;
    		if(cs * 12 < num) cs++;
    		r = 2 * cs + 1;
    		c = 25;
    	}
    	int px = 2, py = 2;
    	for(int e = 1;e <= num;e++){
    		graph[px][py] = 'X';
    		py += 2;
    		if(py > 25){
    			py = 2;
    			px += 2;
    		}
    	}
    	int cnt;
    	cnt = s - num * 8;
    	px = 1; py = 1;
    	for(int i = 1;i <= cnt;i++){
    		graph[px][py] = 'X';
    		py += 2;
    	}
    	cout << r << " " << c << endl;
    	int ans = 0;
    	for(int i = 1;i <= r;i++){
    		for(int j = 1;j <= c;j++){
    			cout<<graph[i][j];
    			//if(graph[i][j] == '.'){
    			//	for(int op = 0;op<8;op++){
    			//		int dx = i + opx[op], dy = j + opy[op];
    			//		if(graph[dx][dy] == 'X') ans ++;
    			//	}
    			//}
    		}
    		cout<<endl;
    	}
    	//cout<<ans<<endl;
    	return;
    }
    int main()
    {
    	int T, s;
    	//for(int i = 1000;i ;i--){
    	//	solve(i);
    	//}
    	cin>>T;
    	while(T--){
    		cin>>s;
    		solve(s);
    	}
    	return 0;
    }
    

      

    1011 Task Scheduler

    竟然有这样的大水题?????

    比赛时我很快想到了正解,也注意到了k=0时的特判,但是我看他们wa了这么多发,就一直不敢写2333

    #include<iostream>
    #include<algorithm>
    using namespace std;
    struct T{
    	int s,id;
    }t[104];
    bool cmp(T a,T b){
    	if(a.s!=b.s) return b.s<a.s;
    	else return b.id > a.id;
    }
    int main()
    {
    	int T;
    	cin >> T;
    	int n,m,k;
    	while(T--){
    		cin>>n>>m>>k;
    		for(int i = 1;i <= n;i++){
    			cin >> t[i].s;
    			t[i].id = i;
    		}
    		if(k == 0){
    			for(int i = 1;i<n;i++){
    				cout<<i<<" ";
    			}
    			cout<<n<<endl;
    			continue;
    		}
    		sort(t+1,t+n+1,cmp);
    		for(int i = 1;i < n;i++){
    			cout<<t[i].id<<" ";
    		}
    		cout<<t[n].id<<endl;
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    hibernate---核心开发接口1(重点)
    hibernate--联合主键(了解+,掌握-)
    hibernate---table_Generator
    hibernate---ID生成策略
    hibernate 注解写在哪?
    hibernate学习笔记--可选的配置属性
    软件开发的硬约束【转载】
    (2016春) 作业7: 用户体验设计案例分析
    (2016春) 第一阶段优胜者
    (2016春) 作业6 :团队作业
  • 原文地址:https://www.cnblogs.com/ruanbaitql/p/13573599.html
Copyright © 2011-2022 走看看