• The 2018 ACM-ICPC China JiangSu Provincial Programming Contest(第六场)


    A .

    Plague Inc. is a famous game, which player develop virus to ruin the world.

    JSZKC wants to model this game. Let's consider the world has N imes MN×M cities. The world has NN rows and MMcolumns. The city in the XX row and the YY column has coordinate (X,Y)(X,Y).

    There are KK cities which are sources of infection at the 0^{th}0th day. Each day the infection in any infected city will spread to the near four cities (if exist).

    JSZKC wants to know which city is the last one to be infected. If there are more than one cities , answer the one with smallest XX firstly, smallest YY secondly.

    Input Format

    The input file contains several test cases, each of them as described below.

    • The first line of the input contains two integers NN and M(1 le N,M le 2000)(1N,M2000), giving the number of rows and columns of the world.
    • The second line of the input contain the integer K(1 le K le 10)(1K10).
    • Then KK lines follow. Each line contains two integers X_iXi and Y_iYi, indicating (X_i,Y_i)(Xi,Yi) is a source. It's guaranteed that the coordinates are all different.

    There are no more than 2020 test cases.

    Output Format

    For each testcase, output one line with coordinate XX and YY separated by a space.

    样例输入

    3 3
    1
    2 2
    3 3
    2
    1 1
    3 3

    样例输出

    1 1
    1 3


    题意:题意比较好懂,就是求最后一个入侵到的点
    思路分析:比赛时写了一个正常的光搜,TLE了,队友提醒手写一个队列,然后过了,赛后发现原来写个曼哈顿距离就可以了..
    代码示例:
    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    const ll maxn = 1e6+5;
    const ll mod = 1e9+7;
    const int inf = 0x3f3f3f3f;
    
    int n, m, k;
    int x[15], y[15];
    int bu[2005][2005];
    
    int main(){
    	
    	while(~scanf("%d%d", &n, &m)){
    		scanf("%d", &k);
    		for(int i = 1; i <= k; i++){
    			scanf("%d%d", &x[i], &y[i]);
    		}
    		int ax = inf, ay = inf;
    		int ans = 0;
    		
    		for(int i = 1; i <= n; i++){
    			for(int j = 1; j <= m; j++){
    				bu[i][j] = inf;
    				for(int t = 1; t <= k; t++){
    					if (abs(i-x[t])+abs(j-y[t]) < bu[i][j]){
    						bu[i][j] = abs(i-x[t])+abs(j-y[t]);
    					//	ans = abs(i-x[t])+abs(j-y[t]);
    					}
    				}
    				if (bu[i][j] > ans){
    					ax = i, ay = j;
    					ans = bu[i][j];
    				}
    				else if (bu[i][j] == ans){
    					if (i < ax){
    						ax = i, ay = j;
    					}
    					else if (ax == i && j < ay) ay = j;
    				}
    			}
    		}
    		printf("%d %d
    ", ax, ay);
    	}	
    }
    

    B .

    JSZKC is the captain of the lala team.

    There are NNN girls in the lala team. And their height is [1,N][1,N][1,N] and distinct. So it means there are no two girls with a same height.

    JSZKC has to arrange them as an array from left to right and let hih_ihi be the height of the ithi^{th}ith girl counting from the left. After that, he can calculate the sum of the inversion pairs. A inversion pair counts if hi>hjh_i>h_jhi>hj with i<ji<ji<j.

    Now JSZKC wants to know how many different arranging plans with the sum of the inversion pairs equaling KKK. Two plans are considered different if and only if there exists an iii with hih_ihi different in these two plans.

    As the answer may be very large, you should output the answer mod 100000000710000000071000000007.

    Input Format

    The input file contains several test cases, each of them as described below.

    • The first line of the input contains two integers NNN and KKK (1≤N≤5000,0≤K≤5000)(1 le N le 5000,0 le K le 5000)(1N5000,0K5000), giving the number of girls and the pairs that JSZKC asked.

    There are no more than 500050005000 test cases.

    Output Format

    An integer in one line for each test case, which is the number of the plans mod 100000000710000000071000000007.

    样例输入

    3 2
    3 3

    样例输出

    2
    1

    题意 :求长度为N的序列中逆序数为K 的有多少个
    思路分析:定义 dp[i][j]表示长度为 i 的序列逆序数为 j 的有多少个,但是在此题中会超内存,考虑一下它递推的过程就发现可以用滚动数组去优化
    代码示例:
    #define ll long long
    const ll maxn = 1e6+5;
    const ll mod = 1e9+7;
    
    ll dp[5005];
    ll sum[5005];
    struct node
    {
        ll n, k;
        ll id, ans;
        bool operator< (const node &v){
            if (v.n == n) return k < v.k;
            return n < v.n;
        }
    }pre[5005];
    
    bool cmp(node a, node b){
        return a.id < b.id;
    }
    
    int main() {
        //freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
        ll c = 1;
        while(scanf("%lld%lld", &pre[c].n, &pre[c].k) != EOF) {pre[c].id = c, c++;}
        
        sort(pre+1, pre+c);
        ll t = 1;
        dp[0] = 0;
        for(ll i = 1; i <= 5000; i++){
            dp[0] = 1;
            if (pre[t].n == i && pre[t].k == 0){
                pre[t].ans = 1;
                t++;
            }
            for(ll j = 1; j <= 5000; j++){
                ll s = max(0ll, j-i+1), e = j;
                if (s == 0) dp[j] = sum[e];
                else dp[j] = (sum[e]-sum[s-1]+mod)%mod;
                
                if (pre[t].n == i && pre[t].k == j){
                    pre[t].ans = dp[j];
                    t++;
                }
            }
            sum[0] = 1;
            for(ll j = 1; j <= 5000; j++){
                sum[j] = sum[j-1]+dp[j];
                sum[j] %= mod;
            }
        }
        sort(pre+1, pre+c, cmp);
        for(ll i = 1; i < c; i++){
            printf("%lld
    ", pre[i].ans);
        }
        return 0;
    }
    

    E .

    JSZKC feels so bored in the classroom that he wants to send massages to his girl friend. However, he can't move to his girl friend by himself. So he has to ask his classmates for help.

    The classroom is a table of size N×MN imes MN×M. We'll consider the table rows numbered from top to bottom 111 through NNN, and the columns numbered from left to right 111 through MMM. Then we'll denote the cell in row xxx and column yyy as (x,y)(x, y)(x,y). And every cell sits a student.

    Initially JSZKC sits on the cell (1,1)(1, 1)(1,1) . And his girl friend sits on cell (n,m)(n, m)(n,m). A message can go from cell (x,y)(x, y)(x,y) to one of two cells (x+1,y)(x + 1, y)(x+1,y) and (x,y+1)(x, y + 1)(x,y+1). JSZKC doesn't want to trouble his classmates too much. So his classmates(not including his girl friend) may not take massages more than once. It's obvious that he can only send out two massages. Please help JSZKC find the number of ways in which the two massages can go from cell (1,1)(1, 1)(1,1) to cell (n,m)(n, m)(n,m).

    More formally, find the number of pairs of non-intersecting ways from cell (1,1)(1, 1)(1,1) to cell (n,m)(n, m)(n,m) modulo 100000000710000000071000000007 . Two ways are called non-intersecting if they have exactly two common points — the starting point and the final point.

    Input Format

    The input file contains several test cases, each of them as described below.

    • The first line of the input contains one integers NNN (2≤N,M≤1000)(2 le N,M le 1000)(2N,M1000), giving the number of rows and columns in the classroom.

    There are no more than 100100100 test cases.

    Output Format

    One line per case, an integer indicates the answer mod 100000000710000000071000000007.

    样例输入

    2 2
    2 3
    3 3

    样例输出

    1
    1
    3

    题意:男孩位于(1, 1)的位置上,女孩位于(n, m)的位置上面,他们的位置是在一张n*m的矩阵上面,寻找两条路径从(1, 1)到(n, m),并且要求两者不能有任何重复的点,问有多少种
    思路分析:从(1, 1)到(n, m)保证二者没有相交的部分,则一定是从(1, 2)到(n-1, m),从(2, 1)到(n, m-1),根据组合数学中的插空法可知此种情况下的方案总数为
    C(n+m-4, n-2)^2 ,再减去他们重叠的部分,一定是 (1, 2)到(n, m-1),从(2, 1)到(n-1, m)
    代码示例:

    #define ll long long
    const ll maxn = 1e6+5;
    const ll mod = 1e9+7;
     
    ll pp[2005];
     
    void init(){
        pp[0]=1;
         
        for(ll i = 1; i <= 2000; i++){
            pp[i]=pp[i-1]*i;
            pp[i] %= mod;
        } 
    }
     
    ll inv(ll x, ll cnt){
        ll ans = 1;
         
        while(cnt > 0){
            if (cnt&1) ans *= x;
            ans %= mod;
            x *= x;
            x %= mod;
            cnt >>= 1;
        }
        return ans;
    }
     
    ll C(ll n, ll m){
        ll res = pp[n]*inv(pp[m], mod-2)%mod*inv(pp[n-m], mod-2);
        
        res %= mod;
        return res;
    }
     
    int main() {
        ll n, m;
        init();
        
        while(~scanf("%lld%lld", &n, &m)){
            
            ll x = C(n+m-4, n-2)*C(n+m-4, n-2)%mod;
            ll y = C(n+m-4, n-1)*C(n+m-4, m-1)%mod;
            printf("%lld
    ", (x+mod-y)%mod);
        } 
        return 0;
    }
    

     J .

    Let's consider some math problems.

    JSZKC has a set A={1,2,...,N}. He defines a subset of A as 'Meo set' if there doesn't exist two integers in this subset with difference one. For example, WhenA={1,2,3},{1},{2},{3},{1,3} are 'Meo set'.

    For each 'Meo set', we can calculate the product of all the integers in it. And then we square this product. At last, we can sum up all the square result of the 'Meo set'.

    So please output the final result.

    Input Format

    The input file contains several test cases, each of them as described below.

    • The first line of the input contains one integers N (1≤N≤100), giving the size of the set.

    There are no more than 100 test cases.

    Output Format

    One line per case, an integer indicates the answer.

    样例输入

    3

    样例输出

    23
    题意 : 题目定义了一个好的数组,即集合中任意两个数之间不存在差值等于 1 的,问最多存在多少种?
    思路分析:队友找规律发现是 a[i] = (a[i-1]+1)*(i+1)-1,写了个JAVA
    代码示例:
    import java.math.*;
    import java.util.*;
    public class Main {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Scanner cin = new Scanner(System.in);
            BigInteger[] a = new BigInteger[105];
            //BigInteger a[105];
            a[1] = BigInteger.ONE;
            a[2] = BigInteger.valueOf(5);
             
            for(int i = 3; i <= 100; i++){
                a[i] = a[i-1].add(BigInteger.ONE);
                //a[i] = a[i].multiple(BigInteger.valueOf(i+1));
                a[i] = a[i].multiply(BigInteger.valueOf(i+1));
                a[i] = a[i].subtract(BigInteger.ONE);
            }
            while(cin.hasNext()){
                int n = cin.nextInt();
                System.out.println(a[n]);
            }
    	}
    }
    



    东北日出西边雨 道是无情却有情
  • 相关阅读:
    Flash中先获取flv的尺寸然后再显示的方法
    雕虫小艺:Slider控件的制作(Flash)
    用几十行代码写一个可以在PC Web,PC桌面,安卓,iOS上运行的程序
    仰望星空,结果南辕北辙
    Flash播放mp4的两个问题:编码问题和需要下载完后才能播放的问题
    只学一点点:我的技术学习策略
    2012年计划
    提高ipad浏览器下大尺寸xml文件解析的性能
    html5/haXe开发偶感
    支点:技术选择的精髓
  • 原文地址:https://www.cnblogs.com/ccut-ry/p/9362159.html
Copyright © 2020-2023  润新知