codeforces 919 a,b,c

A. Supermarket
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that a yuan for b kilos (You don’t need to care about what “yuan” is), the same as a / b yuan for a kilo.

Now imagine you’d like to buy m kilos of apples. You’ve asked n supermarkets and got the prices. Find the minimum cost for those apples.

You can assume that there are enough apples in all supermarkets.

Input
The first line contains two positive integers n and m (1 ≤ n ≤ 5 000, 1 ≤ m ≤ 100), denoting that there are n supermarkets and you want to buy m kilos of apples.

The following n lines describe the information of the supermarkets. Each line contains two positive integers a, b (1 ≤ a, b ≤ 100), denoting that in this supermarket, you are supposed to pay a yuan for b kilos of apples.

Output
The only line, denoting the minimum cost for m kilos of apples. Please make sure that the absolute or relative error between your answer and the correct answer won’t exceed 10 - 6.

Formally, let your answer be x, and the jury’s answer be y. Your answer is considered correct if .

Examples
input
3 5
1 2
3 4
1 3
output
1.66666667
input
2 1
99 100
98 99
output
0.98989899
Note
In the first sample, you are supposed to buy 5 kilos of apples in supermarket 3. The cost is 5 / 3 yuan.

In the second sample, you are supposed to buy 1 kilo of apples in supermarket 2. The cost is 98 / 99 yuan.

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        double min=0x3f3f3f3f;
        for(int i=1;i<=n;i++)
        {
            double a,b;
            scanf("%lf%lf",&a,&b);
            double y=a/b;
            if(y<min)
            {
                min=y;
            }
        }
        printf("%.8f\n",min*m);

    }
}

无穷大:0x3f3f3f3f;

B. Perfect Number
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
We consider a positive integer perfect, if and only if the sum of its digits is exactly 10. Given a positive integer k, your task is to find the k-th smallest perfect positive integer.

Input
A single line with a positive integer k (1 ≤ k ≤ 10 000).

Output
A single number, denoting the k-th smallest perfect integer.

Examples
input
1
output
19
input
2
output
28
Note
The first perfect integer is 19 and the second one is 28.

暴力:但是不能用数组,会爆,找一个i存一个k,如果i==n输出i;
代码:

#include<cstdio>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
#define double long double
using namespace std;

int n;

int _judge(int x)
{
    int num = 0;
    while (x)
    {
        num+=x%10;
        x/=10;
    }
    return num==10;
}

int main()
{
    cin >> n;
    int k = 0;
    for (int i = 1; i <= (int)2e7; i++)
        if (_judge(i))
        {
            k++;
            if (k==n)
            {
                cout<<i<<endl;
                break;
            }
        }
}

C. Seat Arrangements
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and your friends went for class, and found out that some of the seats were occupied.

The classroom contains n rows of seats and there are m seats in each row. Then the classroom can be represented as an n × m matrix. The character ‘.’ represents an empty seat, while ‘*’ means that the seat is occupied. You need to find k consecutive empty seats in the same row or column and arrange those seats for you and your friends. Your task is to find the number of ways to arrange the seats. Two ways are considered different if sets of places that students occupy differs.

Input
The first line contains three positive integers n, m, k (1 ≤ n, m, k ≤ 2 000), where n, m represent the sizes of the classroom and k is the number of consecutive seats you need to find.

Each of the next n lines contains m characters ‘.’ or ‘‘. They form a matrix representing the classroom, ‘.’ denotes an empty seat, and ‘’ denotes an occupied seat.

Output
A single number, denoting the number of ways to find k empty seats in the same row or column.

Examples
input
2 3 2
**.

output
3
input
1 2 2
..
output
1
input
3 3 4
.*.
.
.*.
output
0
Note
In the first sample, there are three ways to arrange those seats. You can take the following seats for your arrangement.

(1, 3), (2, 3)
(2, 2), (2, 3)
(2, 1), (2, 2)

模拟,不要看到图就以为是搜索,就不敢想了;
代码:

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int pre[2005][2005];
int a[2005][2005];
char s[2005][2005];
int main()
{
    int n,m,k;
    while(~scanf("%d%d%d",&n,&m,&k))
    {
        int ans=0;
        for(int i=1; i<=n; i++)
        {
            cin>>(s[i]+1);
        }
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                if(s[i][j]=='*')
                {
                    a[i][j]=1;
                }
                else
                {
                    a[i][j]=0;
                }
            }
        }
        for(int i=1; i<=n; i++)
        {
            pre[i][0]=0;
            for(int j=1; j<=m; j++)
            {
                pre[i][j]=pre[i][j-1]+a[i][j];
            }
        }
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                if(j+k-1<=m)
                {
                    if(pre[i][j-1]==pre[i][j+k-1])
                    {
                        ans++;
                    }
                }

            }
        }
//        printf("%d\n",ans);
        memset(pre,0,sizeof(pre));
        for(int j=1; j<=m; j++)
        {
            pre[0][j]=0;
            for(int i=1; i<=n; i++)
            {
                pre[i][j]=pre[i-1][j]+a[i][j];
            }
        }
        for(int j=1; j<=m; j++)
        {
            for(int i=1; i<=n; i++)
            {
                if(i+k-1<=n)
                {
                    if(pre[i-1][j]==pre[i+k-1][j])
                    {
                        ans++;
                    }
                }
            }
        }
        if(k==1)
        {
            ans/=2;
        }
        printf("%d\n",ans);
    }
}

革命尚未成功,继续努力吧!嗷呜

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值