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?:x<?-:;}
typedef long long ll;
int n,m,k;
int a[][],b[][];
int vis[][];
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+,ans_y=m+;
ans_ans=-;
for(int i=,x,y;i<k;i++)
scanf("%d%d",&b[i][],&b[i][]);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
for(int z=;z<k;z++)
{
vis[i][j]=min(vis[i][j],abs(i-b[z][])+abs(j-b[z][]));
}
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 ;
}

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?:x<?-:;}
typedef long long ll;
struct node
{
int n,k,cnt;
bool operator<(const node &a) const{
return a.n>n;
}
}e[];
int f[][],ans[],top=,inf=;
int main()
{
while(scanf("%d%d",&e[top].n,&e[top].k)!=EOF) e[top++].cnt=top-;
sort(e,e+top);
f[][]=;
for(int i=;i<=;i++)
{
int pos=;
for(int j=;j<=;j++)
{
pos=(pos+f[i-&][j])%MOD;
if(j-i>=) pos=(pos-f[i-&][j-i]+MOD)%MOD;
f[i&][j]=pos;
}
while(inf<top && e[inf].n==i) ans[e[inf].cnt]=f[i&][e[inf++].k];
}
for(int i=;i<top;i++)
printf("%d\n",ans[i]);
return ;
}

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?:x<?-:;}
typedef long long ll;
ll n,m,k;
ll a[],b[];
ll f[];
void exgcd(ll a,ll b,ll &x,ll &y)
{
ll t;
if(!b){
x=;
y=;
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[]=;
for(int i=;i<=;i++)
f[i]=(f[i-]*i)%MOD;
}
int main()
{
init();
while(scanf("%lld",&n)!=EOF)
{
b[]=;
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
b[i]=a[i]+b[i-];
}
ll ans=;
for(int i=n;i;i--)
ans=(ans*f[b[i]]%MOD*inv(f[b[i-]])%MOD*inv(f[a[i]])%MOD)%MOD;
printf("%lld\n",ans);
}
return ;
}

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?:x<?-:;}
typedef long long ll;
ll n,m,k,f[];
void exgcd(ll a,ll b,ll &x,ll &y)
{
ll t;
if(!b){x=;y=;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[]=;
for(int i=;i<=;i++)
f[i]=(f[i-]*i)%MOD;
}
ll solve(ll n,ll m)
{
if(m==) return ;//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-,n-);
ll x_2=solve(n+m-,n-);
ll x_3=solve(n+m-,n-);
//ll x_4=solve(n+m-4,n-3);//不能为负
ll x_4=solve(n+m-,m-);
printf("%lld\n",(x_1*x_2%MOD+MOD-x_3*x_4%MOD)%MOD);
}
return ;
}

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]);
}
}
}

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

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

    题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Per ...

  2. The 2018 ACM-ICPC China JiangSu Provincial Programming Contest J. Set

    Let's consider some math problems. JSZKC has a set A=A={1,2,...,N}. He defines a subset of A as 'Meo ...

  3. The 2018 ACM-ICPC China JiangSu Provincial Programming Contest I. T-shirt

    JSZKC is going to spend his vacation! His vacation has N days. Each day, he can choose a T-shirt to ...

  4. C.0689-The 2019 ICPC China Shaanxi Provincial Programming Contest

    We call a string as a 0689-string if this string only consists of digits '0', '6', '8' and '9'. Give ...

  5. B.Grid with Arrows-The 2019 ICPC China Shaanxi Provincial Programming Contest

    BaoBao has just found a grid with $n$ rows and $m$ columns in his left pocket, where the cell in the ...

  6. ACM ICPC, Damascus University Collegiate Programming Contest(2018) Solution

    A:Martadella Stikes Again 水. #include <bits/stdc++.h> using namespace std; #define ll long lon ...

  7. 计蒜客 39272.Tree-树链剖分(点权)+带修改区间异或和 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest E.) 2019ICPC西安邀请赛现场赛重现赛

    Tree Ming and Hong are playing a simple game called nim game. They have nn piles of stones numbered  ...

  8. 计蒜客 39280.Travel-二分+最短路dijkstra-二分过程中保存结果,因为二分完最后的不一定是结果 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest M.) 2019ICPC西安邀请赛现场赛重现赛

    Travel There are nn planets in the MOT galaxy, and each planet has a unique number from 1 \sim n1∼n. ...

  9. 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛

    Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...

随机推荐

  1. jquery 函数的定义

    var ss_login = { ptjy : function(method) { CloseAlert(); if( getLocalData("ActivePTJYUser" ...

  2. bzoj3295: [Cqoi2011]动态逆序对(cdq分治+树状数组)

    3295: [Cqoi2011]动态逆序对 题目:传送门 题解: 刚学完cdq分治,想起来之前有一道是树套树的题目可以用cdq分治来做...尝试一波 还是太弱了...想到了要做两次cdq...然后伏地 ...

  3. xBIM 高级03 更改日志创建

    系列目录    [已更新最新开发文章,点击查看详细]  模型中发生的每一个变化都是事务的一部分,这是我们设计的核心.所有事务都是由 IModel 的实现创建的,并且从中被弱引用,因此当使用 using ...

  4. 深入理解 JavaScript 异步——转载

    本文章转载于深入理解 JavaScript 异步 前言 2014年秋季写完了<深入理解javascript原型和闭包系列>,已经帮助过很多人走出了 js 原型.作用域.闭包的困惑,至今仍能 ...

  5. linux批处理笔记

    最近不得不用到Linux批处理,于是把要用到的程序反复研究了一下. #!/bin/bash是指此脚本使用/bin/bash来解释执行. -le -ge分别是小于和大于,这个倒是和latex里面的命令很 ...

  6. 【原创】Google的文本内容对比代码

    /* * Diff Match and Patch * * Copyright 2006 Google Inc. * http://code.google.com/p/google-diff-matc ...

  7. 定时清理clientmqueue目录垃圾文件防止占满磁盘空间

    RedHat/CentOS 5.8 默认就有sendmail,而6.4默认没有.   手动清理方法: find /var/spool/clientmqueue/ -type f|xargs rm -f ...

  8. swift where 的作用

    条件限定: 类型限定: 结构化查询模式. 用于结构体.记录字段.

  9. 1113: [视频]树形动态规划(TreeDP)8:树(tree)(树形dp状态设计总结)

    根据最近做的几道树形dp题总结一下规律.(从这篇往前到洛谷 P1352 ) 这几道题都是在一颗树上,然后要让整棵树的节点或边 满足一种状态.然后点可以影响到相邻点的这种状态 然后求最小次数 那么要从两 ...

  10. 紫书 例题8-10 UVa 714 (二分答案)

    这道题让最大值最小, 显然是二分答案 当题目求的是最大值最小, 最小值最大, 这个时候就要想到二分答案 为什么可以二分答案呢, 因为这个时候解是单调性的, 如果简单粗暴一点 就全部枚举一遍, 验证答案 ...