Codeforces Round #460 (Div. 2) 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<bits/stdc++.h>
using namespace std;

const int MAX = 10000+10;
const int INF = 0x3fffffff;

struct node{
    double a,b;
    double value;
}s[MAX];
bool cmp(node a,node b){
    return a.value <b.value;

}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%lf%lf",&s[i].a ,&s[i].b);
        s[i].value=s[i].b /s[i].a;
    }
    sort(s,s+n,cmp);
    printf("%.8lf",m/s[n-1].value );
    return 0;
}


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.


题目大意:把各个位上数字之和为10的数称为完美数,按字典序排序,问第k个完美数是几;
思路:数据范围刚好合适暴力,1e7+1e6的表刚好打到第10000个多一点。


#include<bits/stdc++.h>
using namespace std;

const int MAX = 10000+10;
const int INF = 0x3fffffff;

int a[MAX];
int b[MAX];

int main(){
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    int num=0;
    int temp=0;
    for(int i=19;i<=1e7+1e6;i++){
        int tes = i;
        temp=0;
        while(i){
            temp+=(i%10);
            i/=10;
        }
        if(temp == 10){
            b[num]=tes;
            num++;
        }   
        i= tes;
    }
    int n;
    while(scanf("%d",&n)!=EOF){
        printf("%d\n",b[n-1]);
    }
    return 0;
}


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)


题目大意:在n行m列的教室中找k个连续的座位(都在一横排,或者一竖行),问有几种可行的方法
思路:暴力,横着走一遍竖着走一遍。

PS:用于统计的数据要用long long 这里被hack就很难受


#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int MAX = 3000+10;
const int INF = 0x3fffffff;
int n,k,m;
long long num=0;
long long ans=0;
char mapp[MAX][MAX];

int main(){
    while(scanf("%d%d%d",&n,&m,&k)!=EOF){
        memset(mapp,0,sizeof(mapp));
        ans=0;
        num=0;
        getchar();
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                scanf("%c",&mapp[i][j]);
            }
            getchar();
        }

        for(int i=1;i<=n;i++){
            num=0;
            for(int j=1;j<=m;j++){
                if(mapp[i][j]=='.'){
                    num++;
                }
                else{
                    if(num>=k){
                        ans += (num-k+1);
                        num = 0;
                    }
                    else{
                        num = 0;
                    }
                }
            }
            if(num>=k){
                ans+=(num-k+1);
            }
            num=0;
        }
        if(k==1) return !printf("%lld\n",ans);
        for(int i=1;i<=m;i++){
            num=0;
            for(int j=1;j<=n;j++){
                if(mapp[j][i]=='.'){
                    num++;
                }
                else{
                    if(num>=k){
                        ans+=(num-k+1);
                        num=0;
                    }
                    else{
                        num=0;
                    }
                }
            }
            if(num>=k){
                ans+=(num-k+1);
            }
            num=0;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值