2021-05-22 补题

B - Steps

One day Vasya went out for a walk in the yard but there weren’t any of his friends outside and he had no one to play touch and run. But the boy didn’t lose the high spirits and decided to play touch and run with himself. You may ask: “How did he do that?” The answer is simple.

Vasya noticed that the yard is a rectangular n × m field. The squares have coordinates (x, y) (1 ≤ x ≤ n, 1 ≤ y ≤ m), where x is the index of the row and y is the index of the column.

Initially Vasya stands in the square with coordinates (xc, yc). To play, he has got a list of k vectors (dxi, dyi) of non-zero length. The game goes like this. The boy considers all vectors in the order from 1 to k, and consecutively chooses each vector as the current one. After the boy has chosen a current vector, he makes the maximally possible number of valid steps in the vector’s direction (it is possible that he makes zero steps).

A step is defined as one movement from the square where the boy is standing now, in the direction of the current vector. That is, if Vasya is positioned in square (x, y), and the current vector is (dx, dy), one step moves Vasya to square (x + dx, y + dy). A step is considered valid, if the boy does not go out of the yard if he performs the step.

Vasya stepped on and on, on and on until he ran out of vectors in his list. Ha had been stepping for so long that he completely forgot how many steps he had made. Help the boy and count how many steps he had made.

Input
The first input line contains two integers n and m (1 ≤ n, m ≤ 109) — the yard’s sizes. The second line contains integers xc and yc — the initial square’s coordinates (1 ≤ xc ≤ n, 1 ≤ yc ≤ m).

The third line contains an integer k (1 ≤ k ≤ 104) — the number of vectors. Then follow k lines, each of them contains two integers dxi and dyi (|dxi|, |dyi| ≤ 109, |dx| + |dy| ≥ 1).

Output
Print the single number — the number of steps Vasya had made.

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.

Examples
Input
4 5
1 1
3
1 1
1 1
0 -2
Output
4
Input
10 10
1 2
1
-1 0
Output
0
Note
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0,  - 2) and he ends up in square (4, 2). Overall, Vasya makes 4 steps.

In the second sample Vasya is initially positioned in square (1, 2) and makes 0 steps by vector ( - 1, 0), as the square with coordinates (0, 2) is located outside the yard.

题意

给出n×m整点坐标,给出初始点(x0,y0)再给出k个坐标要求按照k次坐标和(x0,y0)(不包括开始时的初始点)向量上有多少在范围内的整数点,0<x<=n,0<y<=m。

思路

当所给的为正数时,向量的方向是靠近最大坐标即(n,m)。反之为负数,靠近(1,1)。我们只需要分别讨论x,y正负即可。

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m;
ll x0,y0;
ll x,y;
ll k;
int main()
{
   cin>>n>>m;
   cin>>x0>>y0;
   cin>>k;
   ll cnt = 0;
   int sim = 0;
   ll xn,yn;
   ll xx,yx;
   ll mn1,mn2,minn;
   while(k--){
        cin>>x>>y;
        if(x > 0)mn1 = (n-x0)/x;
        else if(x == 0) mn1 = 1e10;
        else if(x < 0) mn1 = (1-x0)/x;
        if(y > 0)mn2 = (m-y0)/y;
        else if(y == 0) mn2 = 1e10;
        else if(y < 0) mn2 = (1-y0)/y;
        minn = min(mn1,mn2);
        /*cout<<minn<<endl;
        cout<<yn<<endl;
        cout<<"yn:"<<yn/y<<endl;
        if(minn == 1e10)minn = 0;*/
        cnt += minn;
        x0 = x0 + x*minn;
        y0 = y0 + y*minn;
   }
   cout<<cnt<<endl;
}

C - Pocket Book

One day little Vasya found mom’s pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let’s number the names from 1 to n in the order in which they are written.

As mom wasn’t home, Vasya decided to play with names: he chose three integers i, j, k (1 ≤ i < j ≤ n, 1 ≤ k ≤ m), then he took names number i and j and swapped their prefixes of length k. For example, if we take names “CBDAD” and “AABRD” and swap their prefixes with the length of 3, the result will be names “AABAD” and “CBDRD”.

You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers i, j, k independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109 + 7).

Input
The first input line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of names and the length of each name, correspondingly. Then n lines contain names, each name consists of exactly m uppercase Latin letters.

Output
Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109 + 7).

Examples
Input
2 3
AAB
BAA
Output
4
Input
4 5
ABABA
BCGDG
AAAAA
YABSA
Output
216
Note
In the first sample Vasya can get the following names in the position number 1: “AAB”, “AAA”, “BAA” and “BAB”.

题意

交换不同前k个字符能形成多少不同的字符串。

思路

每一位上的字符数相乘。

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e9 + 7;
int aa[110];
set<char> c;
char a[110][110];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i = 0;i <n ;i++){
        for(int j = 0;j < m;j++){
            cin>>a[i][j];
        }
    }
    for(int i = 0;i <m ;i++){
        for(int j = 0;j < n;j++){
            c.insert(a[j][i]);
        }
        aa[i] = c.size();
        c.clear();
    }
    ll sum = 1;
    for(int i = 0;i < m;i++){
        sum = (sum * aa[i]) % N;
    }
    cout<<sum<<endl;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值