Codeforces Round #460 (Div. 2) 919A. Supermarket 919B. Perfect Number 919C. Seat Arrangements

这场cf有点意思,hack场,C题等于1的特判hack很多人(我hack成功3个人,上分了,哈哈哈,咳咳。。。)

D题好像是树形dp,E题好像是中国剩余定理,F题好像还是dp,具体的不清楚,最近dp的题目好多,一会滚去学dp。

写A,B,C的题解。

A. Supermarket

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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 51 23 41 3

output

1.66666667

input

2 199 10098 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.

大水题。

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cstdlib>
 6 #include<string.h>
 7 #include<set>
 8 #include<vector>
 9 #include<queue>
10 #include<stack>
11 #include<map>
12 #include<cmath>
13 using namespace std;
14 const int inf=0x3f3f3f3f;
15 int main(){
16     double a,b,ans;
17     double minn=inf;
18     int n,m;
19     cin>>n>>m;
20     for(int i=0;i<n;i++){
21         cin>>a>>b;
22         if(minn>a/b) minn=1.0*a/b;
23     }
24     ans=minn*(double)m;
25     printf("%.8lf",ans);
26 }

B. Perfect Number

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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.

这个题想吐槽一下,我一开始写的多组输入,交上RE了,改了多组输入过了,本来以为自己多组输入初始化什么的写挫了,赛后改了改交上去还是RE,后来直接WA,放弃。多组输入不知道为什么错。。。

代码:

 1 //B-这个题多组输入就不行。。。
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #include<cstring>
 6 #include<cstdlib>
 7 #include<string.h>
 8 #include<set>
 9 #include<vector>
10 #include<queue>
11 #include<stack>
12 #include<map>
13 #include<cmath>
14 using namespace std;
15 int main(){
16     int n,cnt=0;
17     ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
18     cin>>n;
19     for(int i=0;i<30000000;i++){
20         int temp=i;
21         int ans=0;
22         while(temp){
23             int x=temp%10;
24             ans+=x;
25             temp/=10;
26         }
27         if(ans==10)cnt++;
28         if(cnt==n){
29             cout<<i<<endl;
30             break;
31         }
32     }
33 }

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

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)

这个题,特判1那里hack一堆人,改了就可以,不用搜索,直接暴力就可以。

代码:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<queue>
 7 #include<map>
 8 using namespace std;
 9 const int maxn=1e4+5;
10 const double eps=1e6;
11 const int inf=1<<30;
12 char s[maxn][maxn];
13 int main(){
14     int n,m,k;
15     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
16     while(cin>>n>>m>>k){
17         memset(s,0,sizeof(s));
18         for(int i=1;i<=n;i++)
19             cin>>s[i];
20         int ans=0,l=0;
21         for(int i=1;i<=n;i++){
22             l=0;
23             for(int j=0;j<=m-1;j++){
24                 if(s[i][j]==‘.‘)l++;
25                 else{
26                     ans+=max(0,l-k+1);
27                     l=0;
28                 }
29                 if(j==(m-1)&&s[i][j]!=‘*‘)
30                     ans+=max(0,l-k+1);
31             }
32         }
33         for(int j=0;j<=m-1;j++){
34             l=0;
35             for(int i=1;i<=n;i++){
36                 if(s[i][j]==‘.‘) l++;
37                 else{
38                     ans+=max(0,l-k+1);
39                     l=0;
40                 }
41                 if(i==n&&s[i][j]!=‘*‘)
42                 ans+=max(0,l-k+1);
43             }
44         }
45         if(k==1) ans/=2;
46         cout<<ans<<endl;
47     }
48 }

滚去学dp,学会了补后面的题|??ω?` )

原文地址:https://www.cnblogs.com/ZERO-/p/8401284.html

时间: 2024-11-06 07:23:01

Codeforces Round #460 (Div. 2) 919A. Supermarket 919B. Perfect Number 919C. Seat Arrangements的相关文章

Codeforces Round #460 (Div. 2) 919 笔记

A. Supermarket 输入n,m, (1?≤?n?≤?5?000, 1?≤?m?≤?100)表示n组价格数据和目标重量m 接下来n组价格数据,表示为a元b千克,每组无限取 求最小花费 B. Perfect Number 输入k,1?≤?k?≤?10?000,求第k个完美数 完美数定义为数位和=10 (tutorial中说难度可以升级为k<1e18)->用数位dp可解 C. Seat Arrangements 输入n,m,k (1?≤?n,?m,?k?≤?2?000)表示nm的课室,有k

Codeforces Round #460 (Div. 2)_D. Substring_[dp][拓扑排序]

题意:一个有向图,每个结点 被赋予一个小写字母,一条路径的value等与这条路径上出现次数最多的字母的数目,求该图的最大value 比赛时,用dfs超时,看官方题解用的dp和拓扑排序,a--z用0-25表示,用dp[i][j]表示以第i个结点结尾的路径上第j个字母出现的次数 拓扑排序每排到一个点,就用该点的dp去更新与它相邻点的dp,最开始入度为0的点特殊处理了一下,dp过程中同步更新结果res 也复习了一下拓扑排序 #include<iostream> #include<cstdio&

Codeforces Round #460 (Div. 2)

A 签到 B 题意 定义:一个数(没有前缀0)的各个位数之和为10位"perfec"数,问第k个"perfect"数位多少(1<=k<=1e5) 分析 一开始找错了,以为会超过1e9,通过理性的分析不难发现,最大不超过1e9,强行打个表即可 C 签到 D 题意 n个点m条边的有向图,每个点有一个数字(可以重复,0~25),定义一条路径的权值为该路径出现数字最多的数字的次数,若有环输出-1,否则输出最大值 分析 思路:首先直接dfs肯定不行,最坏情况n^2

Codeforces Round #460 (Div. 2) B Perfect Number(二分+数位dp)

题目传送门 B. Perfect Number time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output We consider a positive integer perfect, if and only if the sum of its digits is exactly 1010. Given a positive integ

Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 【莫队算法 + 异或和前缀和的巧妙】

任意门:http://codeforces.com/problemset/problem/617/E E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Bob has a favorite number k and ai of length n. Now he asks yo

Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法

E. XOR and Favorite Number Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri and asks you to count the number of pairs of integers i and j, such that l ≤ i ≤ j ≤ r and the xor

Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形DP)

题目链接:Codeforces Round #419 (Div. 2) E. Karen and Supermarket 题意: 有n件物品,每个物品有一个价格,和一个使用优惠券的价格,不过这个优惠券有一个限制,必须要在第x个使用后才可以使用.现在有m的钱,问最多能买多少个物品. 题解: 每个优惠券都只与一个券有关,所以根据这个关系就可以构成一棵树. 考虑树形dp,dp[i][j][k(0|1)]表示第i个节点所构成的子树中买了j个物品,使用优惠券和不使用优惠券的最少钱. 转移方程看代码详细解释

Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)

题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put o

Codeforces Round #262 (Div. 2) 460B. Little Dima and Equation(枚举)

题目链接:http://codeforces.com/problemset/problem/460/B B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nas