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×Mimes MN×M cities. The world has N rows and M columns. The city in the X row and the Y column has coordinate (X,Y).

There are K cities which are sources of infection at the 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 X firstly, smallest Y 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 N and M (1≤N,M≤2000), giving the number of rows and columns of the world.
    The second line of the input contain the integer K (1≤K≤10).
    Then KKK lines follow. Each line contains two integers XiX_iXi? and YiY_iYi?, indicating (Xi,Yi)(X_i,Y_i)(Xi?,Yi?) is a source. It‘s guaranteed that the coordinates are all different.

There are no more than 20 test cases.
Output Format

For each testcase, output one line with coordinate X and Y separated by a space.
样例输入

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

样例输出

1 1
1 3

第一眼看这道题,果断优先队列加剪枝,TLE。一看过的人好多,应该不会那么难

嗯,暴力扫一下曼哈顿距离就可以了

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?0:x<0?-1:1;}
typedef long long ll;
int n,m,k;
int a[2006][2006],b[12][2];
int vis[2006][2006];
int ans_x,ans_y,ans_ans;
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        memset(vis,INF,sizeof(vis));
        scanf("%d",&k);
        ans_x=n+1,ans_y=m+1;
        ans_ans=-1;
        for(int i=0,x,y;i<k;i++)
            scanf("%d%d",&b[i][0],&b[i][1]);
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                for(int z=0;z<k;z++)
                {
                    vis[i][j]=min(vis[i][j],abs(i-b[z][0])+abs(j-b[z][1]));
                }
                if(vis[i][j]>ans_ans)
                {
                    ans_ans=vis[i][j];
                    ans_x=i;
                    ans_y=j;
                }
                else if(ans_ans==vis[i][j])
                {
                    if(i<ans_x){
                        ans_x=i;
                        ans_y=j;
                    }
                    else if(i==ans_x) ans_y=min(ans_y,j);
                }
            }
        }
        printf("%d %d\n",ans_x,ans_y);
    }
    return 0;
}

B Array

JSZKC is the captain of the lala team.

There are N girls in the lala team. And their height is [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 h[i] be
the height of the ith girl counting from the left. After that, he can
calculate the sum of the inversion pairs. A inversion pair counts if
h[i]>h[j] with i

Input Format

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

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

There are no more than 5000 test cases.

Output Format

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

样例输入

3 2

3 3

样例输出

2

1

动态规划+滚动数组

设f[i][j]为长度为i逆序对个数为j的方案数

5000的数据量数组开不下,滚动数组优化

预处理需要查询的点

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?0:x<0?-1:1;}
typedef long long ll;
struct node
{
    int n,k,cnt;
    bool operator<(const node &a) const{
        return a.n>n;
    }
}e[5006];
int f[2][5006],ans[5006],top=0,inf=0;
int main()
{
    while(scanf("%d%d",&e[top].n,&e[top].k)!=EOF) e[top++].cnt=top-1;
    sort(e,e+top);
    f[0][0]=1;
    for(int i=1;i<=5000;i++)
    {
        int pos=0;
        for(int j=0;j<=5000;j++)
        {
            pos=(pos+f[i-1&1][j])%MOD;
            if(j-i>=0) pos=(pos-f[i-1&1][j-i]+MOD)%MOD;
            f[i&1][j]=pos;
        }
        while(inf<top && e[inf].n==i) ans[e[inf].cnt]=f[i&1][e[inf++].k];
    }
    for(int i=0;i<top;i++)
        printf("%d\n",ans[i]);
    return 0;
}

D Persona5

Persona5 is a famous video game.

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

You have NNN friends and each friends have his upper bound of relationship with you. Let‘s consider the ith friend has the upper bound Ui. 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 1000000007
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≤1000000), giving the number of friends you have.
    The second line contains N integers. The ith integer represents Ui (1≤Ui≤1000000), which means the upper bound with ithi^{th}ith friend. It‘s guarantee that the sum of UiU_iUi? is no more than 1000000.

There are no more than 10 test cases.
Output Format

One line per case, an integer indicates the answer mod 1000000007.
样例输入

3
1 1 1
3
1 2 3

样例输出

6
60

每天加一,则总天数就是sum,因此首先想到全排列,但这样肯定有重复不可行

因此天数固定我可以一个一个人安排,假设每个人的天数为x,可选择的天数为n,则情况为C(n,x)

乘法原理就可以了,题目也说明sum不大于1e6,预处理一下。

C(n,x)=n!/(n-m)!/m!

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?0:x<0?-1:1;}
typedef long long ll;
ll n,m,k;
ll a[1000006],b[1000006];
ll f[1000006];
void exgcd(ll a,ll b,ll &x,ll &y)
{
    ll t;
    if(!b){
        x=1;
        y=0;
        return ;
    }
    exgcd(b,a%b,x,y);
    t=x;x=y;
    y=t-a/b*x;
}
ll inv(ll n)
{
    ll x,y;
    exgcd(n,MOD,x,y);
    return (x+MOD)%MOD;
}
void init()
{
    f[0]=1;
    for(int i=1;i<=1000000;i++)
        f[i]=(f[i-1]*i)%MOD;
}
int main()
{
    init();
    while(scanf("%lld",&n)!=EOF)
    {
        b[0]=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
            b[i]=a[i]+b[i-1];
        }
        ll ans=1;
        for(int i=n;i;i--)
            ans=(ans*f[b[i]]%MOD*inv(f[b[i-1]])%MOD*inv(f[a[i]])%MOD)%MOD;
        printf("%lld\n",ans);
    }
    return 0;
}

E.Massage

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×M. We‘ll consider the table rows numbered from top to bottom 1 through N, and the columns numbered from left to right 1 through M. Then we‘ll denote the cell in row xxx and column yyy as (x,y). And every cell sits a student.

Initially JSZKC sits on the cell (1,1). And his girl friend sits on cell (n,m). A message can go from cell (x,y) to one of two cells (x+1,y) and (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) to cell (n,m) modulo 1000000007. 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), giving the number of rows and columns in the classroom.

There are no more than 100 test cases.
Output Format

One line per case, an integer indicates the answer mod 1000000007.
样例输入

2 2
2 3
3 3

样例输出

1
1
3

网格中只能向又走或者向下走,传两条信息且不相交,则只能从(1,2)到(n-1,m),(2,1)到(n,m-1);

(PS:从(0,0)到(n,n)可以走的路径有C(n+n,n)种,插空法,挑选出第几步走y轴,剩下的x补上)

此时为C(n+m-4,n-2)*C(n+m-4,n-2),减去相交的

从(1,2)到(n,m-1),(2,1)到(n-1,m)一定相交

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
int dcmp(double x){return fabs(x)<esp?0:x<0?-1:1;}
typedef long long ll;
ll n,m,k,f[2006];
void exgcd(ll a,ll b,ll &x,ll &y)
{
    ll t;
    if(!b){x=1;y=0;return ;}
    exgcd(b,a%b,x,y);
    t=x;x=y;y=t-a/b*x;
}
ll inv(ll n)
{
    ll x,y;
    exgcd(n,MOD,x,y);
    return (x+MOD)%MOD;
}
void init()
{
    f[0]=1;
    for(int i=1;i<=2004;i++)
        f[i]=(f[i-1]*i)%MOD;
}
ll solve(ll n,ll m)
{
    if(m==0) return 1;//2 2
    return (f[n]*inv(f[n-m])%MOD*inv(f[m])%MOD)%MOD;
}
int main()
{
    init();
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        ll x_1=solve(n+m-4,n-2);
        ll x_2=solve(n+m-4,n-2);
        ll x_3=solve(n+m-4,n-1);
        //ll x_4=solve(n+m-4,n-3);//不能为负
        ll x_4=solve(n+m-4,m-1);
        printf("%lld\n",(x_1*x_2%MOD+MOD-x_3*x_4%MOD)%MOD);
    }
    return 0;
}

J Set

Let‘s consider some math problems.

JSZKC has a set A={1,2,...,N}. He defines a subset of AAA 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} 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

打表找规律 a[n]=(n+1)!-1;

因为数字太大,写了Java

import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
    static Scanner cin= new Scanner(System.in);
    static BigInteger[] a= new BigInteger[120];
    static BigInteger[] b= new BigInteger[120];
    public static void init()
    {
        a[0]=BigInteger.valueOf(1);
        for(int i=2;i<=101;i++){

            a[i-1]=a[i-2].multiply(BigInteger.valueOf(i));
            b[i-1]=a[i-1].subtract(BigInteger.valueOf(1));
        }
    }
    public static void main(String args[])
    {
        init();
        int n;
        while(cin.hasNext())
        {
            n = cin.nextInt();
            System.out.println(b[n]);
        }
    }
}

原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/9360182.html

时间: 2024-08-30 11:28:34

The 2018 ACM-ICPC China JiangSu Provincial Programming Contest(第六场)的相关文章

The 2018 ACM-ICPC China JiangSu Provincial Programming Contest快速幂取模及求逆元

题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Persona5 is a famous video game. In the game, you are going to build relationship with your friends. You have N friends and each friends have his upper b

The 2019 ACM-ICPC China Shannxi Provincial Programming Contest (西安邀请赛重现) J. And And And

链接:https://nanti.jisuanke.com/t/39277 思路: 一开始看着很像树分治,就用树分治写了下,发现因为异或操作的特殊性,我们是可以优化树分治中的容斥操作的,不合理的情况只有当两点在一条链上才存在,那么直接一遍dfs从根节点向下跑途中维护一下前缀和,把所有情况中不合理情况造成的值修正. 这样的话时间复杂度就可以降得非常低了,感觉还可以优化,但是懒得写了 代码耗时:142ms. 实现代码: #include<bits/stdc++.h> using namespace

2018 ACM/ICPC 南京 I题 Magic Potion

题解:最大流板题:增加两个源点,一个汇点.第一个源点到第二个源点连边,权为K,然后第一个源点再连其他点(英雄点)边权各为1,然后英雄和怪物之间按照所给连边(边权为1). 每个怪物连终点,边权为1: 参考代码: 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define INF 0x3f3f3f3f 4 const int maxn = 2100; 5 int n,m,k,s,t,u,v,w,num,num1; 6 struct Edge

2018-2019 ICPC Northwestern European Regional Programming Contest (NWERC 2018)

J题队友犯了初始化的错,白给6发,本来能1A的 B: solver:lzh.czq 就是个拓扑排序 1 #include <bits/stdc++.h> 2 using namespace std; 3 #define ff first 4 #define ss second 5 #define mp make_pair 6 typedef long long ll; 7 typedef pair<int, int> pii; 8 9 vector<int> g[400

2019-2020 ICPC Southwestern European Regional Programming Contest (SWERC 2019-2020)

J想到了卡特兰数,也想到要按最小值分割数组,丢给队友之后两个人都没做出来,傻了 题目链接:https://codeforces.com/gym/102501 B: solver:czq 1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8

ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018

ACM International Collegiate Programming Contest, Tishreen Collegiate Programming Contest (2018) Syria, Lattakia, Tishreen University, April, 30, 2018 Problem A. Can Shahhoud Solve it? Problem B. Defeat the Monsters Problem C. UCL Game Night Problem

ACM International Collegiate Programming Contest, JUST Collegiate Programming Contest (2018)

ACM International Collegiate Programming Contest, JUST Collegiate Programming Contest (2018) B. New Assignment 有n个人(1?≤?n?≤?104),有男有女,每个人都有一个id,现在这n个人分成学习互助小组,有三种组队模式,一个男人一组,一个女人一组,一男一女一组,如果要一男一女一组,那么这两人id的gcd要>1.保证任意三个人的gcd=1.求小组的组数最少是多少? 看起来是一个很裸的二

poj 5024&amp;&amp;&amp;2014 ACM/ICPC Asia Regional Guangzhou Online 1003(预处理)

http://acm.hdu.edu.cn/showproblem.php?pid=5024 分析:预处理每个点在八个方向的射线长度,再枚举八种L形状的路,取最大值. 注意题意是求一条最长路,要么一条直线,要么只有一个90角,即L型.其实直线就是L形的一个方向长度为0. 代码: #include<iostream> #include<map> #include<cstdio> #include<string> #include<cstring>

[转]浅谈ACM ICPC的题目风格和近几年题目的发展

斯坦福大学 王颖 ACM ICPC的比赛形式一般是五个小时八个题目,综合考察选手的数学能力.算法能力.coding能力和debug能力,还有团队配合能力.数学方面主要强调组合数学.图论和数论这三个方面的能力:而算法的覆盖范围很广,涉及了大部分经典的算法,和少量较前沿的算法.由于每道题目都需要通过所有的测试数据才能得分,并且需要精确解,这限制了Approximation algorithm在一些NP-hard的题目中的运用,从而使得搜索和剪枝策略对于NP-hard的题目非常重要. Final的题目