QLU-第九次训练

因为期末复习半个月没更博客了,,中间还有一次训练没打。。

可上周明明第二天就要六级,,却打了一场训练赛(我也不知道自己怎么想的......)

A - Paper Airplanes

 传送门

To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make ss airplanes.

A group of kk people decided to make nn airplanes each. They are going to buy several packs of paper, each of them containing pp sheets, and then distribute the sheets between the people. Each person should have enough sheets to make nn airplanes. How many packs should they buy?

Input

The only line contains four integers kk, nn, ss, pp (1≤k,n,s,p≤1041≤k,n,s,p≤104) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively.

Output

Print a single integer — the minimum number of packs they should buy.

Examples

Input

5 3 2 3

Output

4

Input

5 3 100 1

Output

5

Note

In the first sample they have to buy 4 packs of paper: there will be 12sheets in total, and giving 2 sheets to each person is enough to suit everyone's needs.

In the second sample they have to buy a pack for each person as they can't share sheets.

 

题目大意是k个人要做纸飞机,每个人需要做n个,一张纸可以做s个,然后一包有p张纸(挺绕的。。)

根据样例可以知道,不是每张纸都是一定要用完的,每个人可以“浪费”一张纸的一部分,也就是说假如一个人需要做5个,一张纸能做3个,那么需要两张纸,然后会剩下还可以做一个纸飞机的量,但是也不可以给其他人用了。

代码:

#include<bits/stdc++.h>
#define exp 1e-8
#define mian main
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define pb push_back
#define PI  acos(-1.0)
#define inf 0x3f3f3f3f
#define w(x) while(x--)
#define int_max 2147483647
#define lowbit(x) (x)&(-x)
#define gcd(a,b) __gcd(a,b)
#define pq(x)  priority_queue<x>
#define ull unsigned long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pl(a,n) next_permutation(a,a+n)
#define ios ios::sync_with_stdio(false)
#define met(a,x) memset((a),(x),sizeof((a)))
using namespace std;
int n,p,s,k;
int main()
{
    while(~scanf("%d%d%d%d",&k,&n,&s,&p)){
        int num=n%s==0?n/s:n/s+1;
        int sum=num*k;
        int ans=sum%p==0?sum/p:sum/p+1;
        printf("%d\n",ans);
    }
}

B - Battleship

 传送门

Arkady is playing Battleship. The rules of this game aren't really important.

There is a field of n×nn×n cells. There should be exactly one kk-decker on the field, i. e. a ship that is kk cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arkady knows if it is definitely empty or can contain a part of the ship.

Consider all possible locations of the ship. Find such a cell that belongs to the maximum possible number of different locations of the ship.

Input

The first line contains two integers nn and kk (1≤k≤n≤1001≤k≤n≤100) — the size of the field and the size of the ship.

The next nn lines contain the field. Each line contains nn characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship).

Output

Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship.

If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell.

Examples

Input

4 3
#..#
#.#.
....
.###

Output

3 2

Input

10 4
#....##...
.#...#....
..#..#..#.
...#.#....
.#..##.#..
.....#...#
...#.##...
.#...#.#..
.....#..#.
...#.#...#

Output

6 1

Input

19 6
##..............###
#......#####.....##
.....#########.....
....###########....
...#############...
..###############..
.#################.
.#################.
.#################.
.#################.
#####....##....####
####............###
####............###
#####...####...####
.#####..####..#####
...###........###..
....###########....
.........##........
#.................#

Output

1 8

Note

The picture below shows the three possible locations of the ship that contain the cell (3,2)(3,2) in the first sample.

 

大致题意是给一个n×n的方格,可以横着放长度为k的船也可以竖着放,问在这些格子中哪个格子被一个船的不同位置占据的次数多。

这个可以暴力过,也就是先每一行找再每一列找,记录下每个格子被放置的次数,最后比较一下就可以了。

#include<bits/stdc++.h>
#define exp 1e-8
#define mian main
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define pb push_back
#define PI  acos(-1.0)
#define inf 0x3f3f3f3f
#define w(x) while(x--)
#define int_max 2147483647
#define lowbit(x) (x)&(-x)
#define gcd(a,b) __gcd(a,b)
#define pq(x)  priority_queue<x>
#define ull unsigned long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pl(a,n) next_permutation(a,a+n)
#define ios ios::sync_with_stdio(false)
#define met(a,x) memset((a),(x),sizeof((a)))
using namespace std;
char a[110][110];
int num[110][110],n,k;
int main()
{
    while(~scanf("%d%d",&n,&k)){
            met(num,0);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        cin>>a[i][j];
        for(int i=1;i<=n;i++){
            int p=0;
            for(int j=1;j<=n;j++){
            if(a[i][j]=='.')
            p++;
           if(a[i][j]=='#')
            p=0;
             if(p>=k)
                for(int l=j-k+1;l<=j;l++)      //一旦大于等于k,就把从这个位置到前k个位置,每个位置都+1
                num[i][l]++;
           }
        }
        for(int i=1;i<=n;i++){
                int p=0;
        for(int j=1;j<=n;j++){
            if(a[j][i]=='.')
                p++;
            if(a[j][i]=='#')
                p=0;
            if(p>=k)
                for(int l=j-k+1;l<=j;l++)
                num[l][i]++;
           }
        }
        int x=1,y=1;
        int maxn=num[1][1];
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            if(num[i][j]>maxn){
                maxn=num[i][j];
                x=i;
                y=j;
            }
            printf("%d %d\n",x,y);
}
}

 

C - Petya and Origami

 传送门

Petya is having a party soon, and he has decided to invite his nn friends.

He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number of notebooks of each color, but each notebook consists of only onecolor with kk sheets. That is, each notebook contains kk sheets of either red, green, or blue.

Find the minimum number of notebooks that Petya needs to buy to invite all nn of his friends.

Input

The first line contains two integers nn and kk (1≤n,k≤1081≤n,k≤108) — the number of Petya's friends and the number of sheets in each notebook respectively.

Output

Print one number — the minimum number of notebooks that Petya needs to buy.

Examples

Input

3 5

Output

10

Input

15 6

Output

38

Note

In the first example, we need 22 red notebooks, 33 green notebooks, and 55 blue notebooks.

In the second example, we need 55 red notebooks, 1313 green notebooks, and 2020 blue notebooks.

水题,要送请柬给n个人,每张请柬需要2张红纸,5张绿纸,8张蓝纸,一个笔记本可以提供一种颜色的纸k张,问需要几个笔记本,,,我也不多说了,,直接上代码吧

#include<bits/stdc++.h>
#define exp 1e-8
#define mian main
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define pb push_back
#define PI  acos(-1.0)
#define inf 0x3f3f3f3f
#define w(x) while(x--)
#define int_max 2147483647
#define lowbit(x) (x)&(-x)
#define gcd(a,b) __gcd(a,b)
#define pq(x)  priority_queue<x>
#define ull unsigned long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pl(a,n) next_permutation(a,a+n)
#define ios ios::sync_with_stdio(false)
#define met(a,x) memset((a),(x),sizeof((a)))
using namespace std;
ll n,k,ans;
int main()
{
    while(~scanf("%lld%lld",&n,&k)){
        ll num1=n*2;
        ll num2=n*5;
        ll num3=n*8;
        ans=0;
        ans=(num1%k==0?num1/k:num1/k+1)+(num2%k==0?num2/k:num2/k+1)+(num3%k==0?num3/k:num3/k+1);
        printf("%lld\n",ans);
    }
}

D - Margarite and the best present

传送门

Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.

Recently, she was presented with an array aa of the size of 109109 elements that is filled as follows:

  • a1=−1a1=−1
  • a2=2a2=2
  • a3=−3a3=−3
  • a4=4a4=4
  • a5=−5a5=−5
  • And so on ...

That is, the value of the ii-th element of the array aa is calculated using the formula ai=i⋅(−1)iai=i⋅(−1)i.

She immediately came up with qq queries on this array. Each query is described with two numbers: ll and rr. The answer to a query is the sum of all the elements of the array at positions from ll to rr inclusive.

Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.

Help her find the answers!

Input

The first line contains a single integer qq (1≤q≤1031≤q≤103) — the number of the queries.

Each of the next qq lines contains two integers ll and rr (1≤l≤r≤1091≤l≤r≤109) — the descriptions of the queries.

Output

Print qq lines, each containing one number — the answer to the query.

Example

Input

5
1 3
2 5
5 5
4 4
2 3

Output

-2
-2
-5
4
-1

Note

In the first query, you need to find the sum of the elements of the array from position 11 to position 33. The sum is equal to a1+a2+a3=−1+2−3=−2a1+a2+a3=−1+2−3=−2.

In the second query, you need to find the sum of the elements of the array from position 22 to position 55. The sum is equal to a2+a3+a4+a5=2−3+4−5=−2a2+a3+a4+a5=2−3+4−5=−2.

In the third query, you need to find the sum of the elements of the array from position 55 to position 55. The sum is equal to a5=−5a5=−5.

In the fourth query, you need to find the sum of the elements of the array from position 44 to position 44. The sum is equal to a4=4a4=4.

In the fifth query, you need to find the sum of the elements of the array from position 22 to position 33. The sum is equal to a2+a3=2−3=−1a2+a3=2−3=−1.

大致题意是:一个数组里面的数依次是-1,2,-3,4......      也就是ai=i⋅(−1)^i

问有q次询问,每个询问查询从l到r的数的和,

10^9的范围,一开始以为要用大数做,但又想了想发现每连续两个数加起来是1,那么就容易了。

利用前缀和,算从1到r的和减去从1到l-1的和即可。如果r或l是偶数,直接除2,即得和,如果r或l是奇数就先算前面r-1个,最后在加上第r个。

#include<bits/stdc++.h>
#define exp 1e-8
#define mian main
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define pb push_back
#define PI  acos(-1.0)
#define inf 0x3f3f3f3f
#define w(x) while(x--)
#define int_max 2147483647
#define lowbit(x) (x)&(-x)
#define gcd(a,b) __gcd(a,b)
#define pq(x)  priority_queue<x>
#define ull unsigned long long
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pl(a,n) next_permutation(a,a+n)
#define ios ios::sync_with_stdio(false)
#define met(a,x) memset((a),(x),sizeof((a)))
using namespace std;
int q,l,r;
int main()
{
    sc(q);
    while(q--){
            scanf("%d%d",&l,&r);
        int ans1=(l-1)%2==0?(l-1)/2:(l-2)/2-l+1;
        int ans2=r%2==0?r/2:r/2-r;
        printf("%d\n",ans2-ans1);
    }
}

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值