Codeforces Round #460 (Div. 2)
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.
InputThe first line contains two positive integers n
The following n lines describe the information of the supermarkets. Each line contains two positive integers a, b
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 input3 5output
1 2
3 4
1 3
1.66666667input
2 1output
99 100
98 99
0.98989899Note
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; double m; scanf("%d%lf",&n,&m); double minx = 0x3f3f3f3f; for(int i = 0; i < n; i++) { double a,b; scanf("%lf%lf",&a,&b); minx = min(minx,a/b); } printf("%lf\n",m*minx); return 0; }View Code
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.
InputA single line with a positive integer k (1 ≤ k ≤ 10 000).
OutputA single number, denoting the k-th smallest perfect integer.
Examples input1output
19input
2output
28Note
The first perfect integer is 19 and the second one is 28.
暴力打表
#include <bits/stdc++.h> using namespace std; bool calc(int x) { int sum = 0; while(x) { sum+=(x%10); x/=10; } return sum==10; } int main() { vector<int> ans; for(int i = 19; i < 20000000; i++) { if(calc(i)) ans.push_back(i); } //printf("%d\n",ans.size()); int k; scanf("%d",&k); printf("%d\n",ans[k-1]); return 0; }View Code
C. Seat Arrangements
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.
InputThe 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.
OutputA single number, denoting the number of ways to find k empty seats in the same row or column.
Examples input2 3 2output
**.
...
3input
1 2 2output
..
1input
3 3 4output
.*.
*.*
.*.
0Note
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)
k連坐
做的時候把我做傻了,一步三坑。以至於我算重復了。
1 ,行數只有一行
2 ,k = 1
搞得我換了兩種寫法。第二種好看一點。
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; char maps[maxn][maxn]; int main() { //freopen("in.txt","r",stdin); int n,m,K; scanf("%d%d%d",&n,&m,&K); int ans = 0; for(int i = 0; i < n; i++) scanf("%s",maps[i]); if(K == 1) { for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(maps[i][j]==‘.‘) ans++; } } printf("%d\n",ans); return 0; } for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(maps[i][j]==‘.‘) { int cnt = 0; int k; for(k = j; k < m; k++) { if(maps[i][k]==‘.‘) cnt++; else break; } if(cnt>=K) { ans = ans + cnt-K+1; } j = k; } } } if(n!=1) { for(int j = 0; j < m; j++) { for(int i = 0; i < n; i++) { if(maps[i][j]==‘.‘) { int cnt = 0; int k; for(k = i; k < n; k++) { if(maps[k][j]==‘.‘) cnt++; else break; } if(cnt>=K) ans=ans + cnt - K +1; i = k; } } } } printf("%d\n",ans); return 0; }View Code
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; char maps[maxn][maxn]; int main() { //freopen("in.txt","r",stdin); int n,m,K; scanf("%d%d%d",&n,&m,&K); for(int i = 0; i < n; i++) scanf("%s",maps[i]); if(K == 1) { int ans = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(maps[i][j]==‘.‘) ans++; } } printf("%d\n",ans); return 0; } int ans = 0; int cnt = 0; int i,j; for(i = 0; i < n; i++) { cnt = 0; for(j = 0; j < m; j++) { if(maps[i][j]==‘*‘||maps[i][j+1]==‘\0‘) { if(maps[i][j]==‘.‘) cnt++; ans += cnt>=K ? cnt - K + 1:0; cnt = 0; continue; } cnt ++; } } if(n!=1) { for(i = 0; i < m; i++) { cnt = 0; for(j = 0; j < n; j++) { if(maps[j][i]==‘*‘||maps[j+1][i]==‘\0‘) { if(maps[j][i]==‘.‘) cnt++; ans += cnt>=K ? cnt - K + 1:0; cnt = 0; continue; } cnt++; } } } printf("%d\n",ans); return 0; }View Code
Codeforces Round #460 (Div. 2)