zoukankan      html  css  js  c++  java
  • Codeforces Round #460 (Div. 2) ABC

    A. Supermarket

    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
    Copy
    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;
    
    int main() {
    	int n, m, x, y;
    	double ans = 1e9;
    	cin >> n >> m;
    	for(int i = 0; i < n; i ++) {
    		cin >> x >> y;
    		ans = min(ans,1.0*x/y);
    	}
    	printf("%.8f
    ",ans*m);
    	return 0;
    }
    

      

    B. Perfect Number
     

    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.

    #include <bits/stdc++.h>
    using namespace std;
    int k, ans;
    int main() {
    	cin >> k;
    	for(int i = 1; ; i ++) {
    		int x = i;
    		int tmp = 0;
    		while(x > 0) {
    			tmp += x%10;
    			x /= 10;
    		}
    		if(tmp == 10) ans++;
    		if(ans == k) return 0*printf("%d
    ",i);
    	}
    	return 0;
    }
    

      

    C. Seat Arrangements
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard 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
    Copy
    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 <bits/stdc++.h>
    using namespace std;
    char str[2010][2010];
    int n, m, k;
    
    int main() {
    	cin >> n >> m >> k;
    	int ans = 0;
    	for(int i = 1; i <= n; i ++) cin >> str[i]+1;
    	for(int j = 1; j <= m; j ++) {
    		for(int i = 1; i <= n; i ++) {
    			if(i+k-1 <= n) {
    				int tmp = 0;
    				for(int l = i; l <= n; l ++) {
    					if(str[l][j] == '.') tmp++;
    					else break;
    				}
    				if(tmp >= k) {
    					ans += tmp-k+1;
    					i += tmp-k+1;
    				}
    			} else break;
    		}
    	}
    	for(int i = 1; i <= n; i ++) {
    		for(int j = 1; j <= m; j ++) {
    			if(j+k-1 <= m) {
    				int tmp = 0;
    				for(int l = j; l <= m; l ++) {
    					if(str[i][l] == '.') tmp++;
    					else break;
    				}
    				if(tmp >= k) {
    					ans += tmp-k+1;
    					j += tmp-k+1;
    				}
    			} else break;
    		}
    	}
    	if(k == 1) printf("%d
    ",ans/2);
    	else printf("%d
    ",ans); 
    	return 0;
    }
    

      

  • 相关阅读:
    Web Services开发(Java篇)
    前端UI框架小汇总
    WebService 在C#.NET中的使用
    求n*m网格内矩形的数目
    Silverlight学习笔记(三):控件布局管理
    Silverlight学习笔记(二):创建Hello World 项目(备注)
    ExcelHelp 学习笔记二: C# 往Excel中写入数据
    DataBase 学习笔记一:c#连接SQL数据库
    ExcelHelp 学习笔记一: C#读取Excel中数据
    Silverlight学习笔记(二):创建Hello World 简单基础应用
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/8797099.html
Copyright © 2011-2022 走看看