The 2018 ACM-ICPC China JiangSu Provincial Programming Contest---徐州

 A. Plague Inc

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\times MN×M cities. The world has NNrows and MM columns. 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 MM (1 \le N,M \le 2000)(1≤N,M≤2000), giving the number of rows and columns of the world.
  • The second line of the input contain the integer KK (1 \le K \le 10)(1≤K≤10).
  • 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

题目来源

The 2018 ACM-ICPC China JiangSu Provincial Programming Contest

题意:给你多个病原体,每个病原体都可以 上,下,左,右 扩散,问最后一个扩散到的点是那个?(如果有多个,取 x 最小                  的,如果 x 相等,取 y 最小的)。

题解:bfs 搜索(带了点优化时间)

1> .超时代码:

#include<stdio.h>
#include<queue>
#include<string.h>
#include<algorithm>
using namespace std;
int n,m,k,ans;
int s[2005][2005];
int v[2005][2005];
struct fun{
    int x,y;
}f[15];

bool cmp(fun a,fun b){
    if(a.x!=b.x)
        return a.x>b.x;
    else
        return a.y>b.y;
}

void bfs(){
    memset(v,0,sizeof(v));
    queue<fun>qq;
    while(!qq.empty()) qq.pop();

    for(int i=0;i<k;i++){
        fun t;
        t.x=f[i].x;
        t.y=f[i].y;
        v[t.x][t.y]=1;
        qq.push(t);
    }
    int sum=0,p;

    fun a[10];
    while(!qq.empty()){
        fun g=qq.front();
        qq.pop();
        sum++,p=0;
      //  printf("sum===%d  x===%d  y===%d\n",sum,g.x,g.y);
        if(sum==ans){
            printf("%d %d\n",g.x,g.y);
            return ;
        }

        int xx,yy;
        for(int i=0;i<4;i++){
            if(i==0){
                xx=g.x+1;
                yy=g.y;
            }
            else if(i==1){
                xx=g.x-1;
                yy=g.y;
            }
            else if(i==2){
                xx=g.x;
                yy=g.y-1;
            }
            else if(i==3){
                xx=g.x;
                yy=g.y+1;
            }
            if(xx<1||xx>n||yy<1||yy>m||v[xx][yy]==1)
                continue;
           // printf("xx====%d  yy====%d\n",xx,yy);
            a[p].x=xx;
            a[p++].y=yy;
            v[xx][yy]=1;
            /*fun t;
            t.x=xx;
            t.y=yy;
            qq.push(t);*/
        }
        sort(a,a+p,cmp);
        for(int i=0;i<p;i++){
            fun t;
            t.x=a[i].x;
            t.y=a[i].y;
            //printf("t.x====%d  t.y====%d\n",t.x,t.y);
           // v[f[i].x][f[i].y]=1;
            qq.push(t);
        }
    }
    return ;
}
int main(){
    while(scanf("%d %d",&n,&m)!=EOF){
        scanf("%d",&k);
        for(int i=0;i<k;i++){
            scanf("%d %d",&f[i].x,&f[i].y);
        }
        sort(f,f+n,cmp);
        ans=n*m;
        bfs();
    }
    return 0;
}

2> .AC代码:

#include<stdio.h>
#include<queue>
#include<string.h>
#include<algorithm>
using namespace std;
int n,m,k,ans;
int vect[2005][2005];
struct fun{
    int x,y;
};
queue<fun>qq;
void bfs(){
    while(!qq.empty()){
        fun g=qq.front();
        ans=max(ans,vect[g.x][g.y]);
        qq.pop();
        int xx,yy;
        for(int i=0;i<4;i++){
            if(i==0){
                xx=g.x+1;
                yy=g.y;
            }
            else if(i==1){
                xx=g.x-1;
                yy=g.y;
            }
            else if(i==2){
                xx=g.x;
                yy=g.y-1;
            }
            else if(i==3){
                xx=g.x;
                yy=g.y+1;
            }
            if(vect[xx][yy]||xx<1||xx>n||yy<1||yy>m)
                continue;
            fun t;
            t.x=xx;
            t.y=yy;
            vect[xx][yy]=vect[g.x][g.y]+1;
            qq.push(t);
        }
    }
}
int main(){
    while(scanf("%d %d",&n,&m)!=EOF){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                vect[i][j]=0;
            }
        }
        scanf("%d",&k);
        for(int i=0;i<k;i++){
            int x,y;
            scanf("%d %d",&x,&y);
            vect[x][y]=1;
            fun t;
            t.x=x;
            t.y=y;
            qq.push(t);
        }
        ans=0;
        bfs();
        for(int i=1;i<=n;i++){
            int leap=0;
            for(int j=1;j<=m;j++){
                if(vect[i][j]==ans){
                    printf("%d %d\n",i,j);
                    leap=1;
                    break;
                }
            }
            if(leap)
                break;
        }
    }
    return 0;
}

D. Persona5

Persona5 is a famous video game.

In the game, you are going to build relationship with your friends.

You have NN friends and each friends have his upper bound of relationship with you. Let's consider the i^{th}ith friend has the upper bound U_iUi​. At the beginning, the relationship with others are zero. In the game, each day you can select one person and increase the relationship with him by one. Notice that you can't select the person whose relationship with you has already reach its upper bound. If your relationship with others all reach the upper bound, the game ends.

It's obvious that the game will end at a fixed day regardless your everyday choices. Please calculate how many kinds of ways to end the game. Two ways are said to be different if and only if there exists one day you select the different friend in the two ways.

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

Input Format

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

  • The first line of the input contains one integers NN (1 \le N \le 1000000)(1≤N≤1000000), giving the number of friends you have.
  • The second line contains NN integers. The i^{th}ith integer represents U_iUi​ ( 1 \le U_i \le 1000000)(1≤Ui​≤1000000), which means the upper bound with i^{th}ith friend. It's guarantee that the sum of U_iUi​ is no more than 10000001000000.

There are no more than 1010 test cases.

Output Format

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

样例输入

3
1 1 1
3
1 2 3

样例输出

6
60

题目来源

The 2018 ACM-ICPC China JiangSu Provincial Programming Contest

题意:一个序列 A 全是0,变到给出的数列 S,(每次只能增加 1),问变到 S 有多少种变化?

题解:(s1+s2+....+sn)! / s1!*s2!*s3!****sn!

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
int a[1000005],b[1000005];
ll po_w(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1){
            ans=ans*a%mod;
        }
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        ll sum=0;
        memset(b,0,sizeof(b));
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
            sum+=1ll*a[i];
            b[a[i]]++;   
        }
        ll ans=1;
        for(ll i=1;i<=sum;i++){
            ans*=i%mod;
        }
        for(int i=1000000;i>=1;i--){
            b[i]+=b[i+1];
            //  比如:  a 数列:1 2 3
            //          b[i] == 1 1 1  (下标从 1 开始)
            //  经过倒置循环这一步后:
            //          b[i] == 3 2 1   意味着:1 要乘 3 次;;2 要乘 2 次;;3 要乘 1 次;;
        }
        ll act=1;
        for(int i=2;i<=1000000;i++){
            if(b[i]!=0){
                act*=(1ll*po_w(i,b[i]))%mod;
                act%=mod;
            }
        }
        printf("%lld\n",ans%mod*po_w(act,mod-2)%mod);
    }
    return 0;
}

 J. Set

Let's consider some math problems.

JSZKC has a set A=\{1,2,...,N\}A={1,2,...,N}. He defines a subset of AA as 'Meo set' if there doesn't exist two integers in this subset with difference one. For example, When A=\{1,2,3\}, \{1\},\{2\},\{3\},\{1,3\}A={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 NN (1 \le N \le 100)(1≤N≤100), giving the size of the set.

There are no more than 100100 test cases.

Output Format

One line per case, an integer indicates the answer.

样例输入

3

样例输出

23

题目来源

The 2018 ACM-ICPC China JiangSu Provincial Programming Contest

题解:推

import java.math.*;
import java.util.*;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		BigDecimal a[]=new BigDecimal[105];
		a[1]=new BigDecimal(1);
		for(int i=2;i<=100;i++){
			a[i]=a[i-1].multiply(new BigDecimal(i+1)).add(new BigDecimal(i));
		}
		while(in.hasNext()){
			int n=in.nextInt();
			System.out.println(a[n]);
		}
	}
}

猜你喜欢

转载自blog.csdn.net/black_horse2018/article/details/81216086