码迷,mamicode.com
首页 > 其他好文 > 详细

2016 USP-ICMC-Codeforces-Gym101063C-Sleep Buddies Gym101063F-Bandejao Gym101063J-The Keys

时间:2017-12-17 22:08:22      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:oss   die   stack   div   include   dsl   ready   ems   struct   

Gym101063C-Sleep Buddies

It is nighttime in the Earth Colony on Mars and everyone is getting ready to sleep. It is common to sleep in pairs, so that if anything were to happen during the night people could aid each other.

To decide who is a suitable candidate to sleep with whom, the leaders of GEMA asked everyone to answer a questionnaire about attributes they desire their partner to have from a list of M possible items.

To choose the pairs, GEMA uses the Jaccard index between the desired attributes of both persons. The Jaccard index for two sets A and B is defined as 技术分享图片, that is, the size of the intersection between A and B divided by the size of their union. They allow a pair to be formed if the Jaccard index of the two attribute sets for the pair is at least K.

Thanks to GEMA, there are too many people living on Mars these days. Help the high commanders decide how many allowed pairs there are out of the N people living there.

Input

The input begins with two integers, N and M (1?≤?N?≤?1051?≤?M?≤?10), the number of people on Mars and the number of possible attributes on the questionnaire.

Then follow N lines, each beginning with an integer Q (1?≤?Q?≤?M), the number of desired attributes on the list of the i-th person. Then follow Q integers q (1?≤?q?≤?M), encoding these attributes. There numbers are all different.

The last line of input contains a real number K (0?≤?K?≤?1), the minimum required Jaccard index for a pair.

Output

Output the number of pairs that are allowed.

Example

Input
2 5
2 1 3
5 3 1 5 4 2
0.66489
Output
0
Input
3 1
1 1
1 1
1 1
0.85809
Output
3
 


代码:(这个好像不是我写的。。。)
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 const int M = 1e5 + 50;
 5 int main()
 6 {
 7     int t,k=0,n,x,a[M],m,p[20];
 8     ll b[M];
 9     double dd;
10     scanf("%d%d",&t,&m);
11     for(int i=1;i<=m+1;i++){
12         p[i] = pow(2,i-1);
13     }
14     memset(b,0,sizeof(b));
15     while(t--){
16         scanf("%d",&n);
17         memset(a,0,sizeof(a));
18         for(int i = 0;i < n;i++){
19             scanf("%d",&x);
20             a[x] = 1;
21         }
22         int ans = 0;
23         for(int i=1;i<=m;i++){
24             ans += (p[i]*a[i]);
25         }
26         //cout<<ans<<endl;
27         b[ans]++;
28     }                                //设一个十进制的数,b数组是因为总共不超过1024,然后他有1e5的集合,有重复;
29     cin>>dd;
30     int c[15];
31     for(int k=1;k<=m;k++)
32         c[k]=pow(2,k-1);
33     ll sum = 0;
34     for(int i = 1;i <= p[m+1]; i++){
35         for(int j = i;j <= p[m+1]; j++){
36             int num1 = (i|j),num2=(i&j);
37             double cnt1=0,cnt2=0;
38             for(int k=1;k<=m;k++)
39             {
40                 if(num1&c[k])
41                     cnt1++;
42                 if(num2&c[k])
43                     cnt2++;
44             }
45             //cout<<cnt1/cnt2<<endl;
46             if(cnt2/cnt1>=dd&&i!=j&&b[i])
47                 sum+=b[i]*b[j];
48             else if(cnt1/cnt2>=dd&&i==j&&b[i]){
49                 sum+=b[i]*(b[i]-1)/2;
50             }
51         }
52     }
53     cout<<sum<<endl;
54 }





Gym101063F-Bandejao

It is lunch time on Mars! Everyone has got that big smile on their faces, all eager to see what the GEMA restaurant is serving for dessert. Everything is pretty much like Earth, but nobody knows why, GEMA decided to invent new types of utensils. Somehow, the food research group concluded that the usual fork, knife and spoon would not be so adequate on Mars.

There are K types of utensils and if you want to have some food, you must use all Kof them (one of each). You like to have lunch with your N friends, and when you are leaving, you want to distribute the utensils among you and all your friends equally (everyone having the same amount of utensils). In addition to that, you want each one of your friends (you included) to carry only one type of utensil (it speeds up the process of leaving the restaurant, and your friends get really mad when it takes more time than usual for them to get back to work).

Given N and K, answer if it is possible for you and your friends to leave the restaurant with everyone carrying the same number of utensils and each one carrying only one type of utensil.

Input

Two integers N and K (0?≤?NK?≤?100 and K?>?0). (You and your friends form a group of N?+?1 people).

Output

Print "yes" (if it is possible) or "no" without quotes.

Example

Input
1 2
Output
yes
Input
1 3
Output
no


代码:
 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 typedef long long ll;
15 const int N=1e5+10;
16 int main(){
17     int n,k;
18     while(~scanf("%d%d",&n,&k)){
19         n+=1;
20         if(n%k==0)printf("yes\n");
21         else printf("no\n");
22     }
23     return 0;
24 }

 

 

 

 

 

Gym101063J-The Keys

Out of all science labs constructed by the GEMA mission on Mars, the DSL - Dangerous Species Lab is the most dangerous of them all. The laboratory is so dangerous that you have to go through N doors in succession to get to it. Each one of those doors can only be opened by one key di (notice, however, that there may be different doors that can be opened by the same key).

A nameless lazy biologist (we‘ll call him LB) from GEMA needs to open all those doors first thing in the morning, every day. He has all the keys necessary to open them, but he finds carrying all of them in his pockets too much of a mess.

To be more organized and lose the title of being a lazy biologist, LB purchased Kkey-chains and is planning to distribute all the keys among them. His plan of distribution is very simple. For each key, randomly choose a key-chain with uniform probability and put this key on it.

When opening the doors, LB will hold one key-chain and will keep the others in his pocket (initially all of them are in his pocket). Whenever he gets to a door that needs a key that is not on the key-chain he is holding, he will swap it with the key-chain that has this key. Getting the first key-chain from his pocket is not considered a swap.

You have to help LB and find what is the expected number of key-chain swaps he will have to do when opening the doors the next morning.

Input

Input begins with N and K (1?≤?N?≤?1051?≤?K?≤?N), the number of doors and the number of key-chains. On the next line there are N numbers di (1?≤?di?≤?106), the identifier of the key that opens the i-th door.

Output

Output the expected number of swaps. Your answer will be considered correct if the absolute and relative error are less than 10?-?6.

Example

Input
3 3
1 2 3
Output
1.333333333
Input
1 1
2
Output
0.000000000
Input
5 2
1 2 3 2 1
Output
2.000000000



代码:
 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 typedef long long ll;
15 const int N=1e5+10;
16 const int INF=0x3f3f3f3f;
17 int a[N];
18 int main(){
19     int n,k;
20     double ans;
21     while(~scanf("%d%d",&n,&k)){
22         for(int i=1;i<=n;i++)
23             scanf("%d",&a[i]);
24         ans=0;
25         if(n==1)printf("%.9f\n",(k-1)*1.0/k);
26         //if(n==1)printf("%.9f\n",ans);
27         else{
28             for(int i=2;i<=n;i++){
29                 if(a[i]!=a[i-1])
30                 ans+=(k-1)*1.0/k;
31             }
32             printf("%.9f\n",ans);
33         }
34     }
35     return 0;
36 }

其他的写不出来了。



 

2016 USP-ICMC-Codeforces-Gym101063C-Sleep Buddies Gym101063F-Bandejao Gym101063J-The Keys

标签:oss   die   stack   div   include   dsl   ready   ems   struct   

原文地址:http://www.cnblogs.com/ZERO-/p/8053073.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!