Jishou University of the Ninth "Rising Star Cup" Collegiate Programming Contest

 

 

Y teacher Lego town

Links: https://ac.nowcoder.com/acm/contest/3667/I
Source: Cattle-off network

Title Description

Y teacher since childhood love of Lego to build their favorite model, this is not a sudden one day Y teachers want to use Lego to build a magical town. The town of infinite different buildings all (assuming that there are magic teacher Y), but the Y is a teacher with obsessive-compulsive disorder in two young people, so if a street built a number of Lego building, then the next street will repair twice the number of Lego building, and the first street now known only a Lego construction. Since New Year's Day approaching, Y teachers want to continue to add to its Lego city lights and festoons, assuming Y k teachers now have got an ornament and Y must be a teacher one day all buildings are put up a street decorations ( Y If the teacher can not put up decorations for all buildings of the street, then, Y teacher would not choose this street, and Y teacher will choose one day a street), is this k ornament hanging up the minimum number of days it?

Enter a description:

Multiple sets of input 
per line integer k (1 <= k <= 1e15)

Output Description:

The minimum number of days
Example 1

Entry

3 

Export

2 

Explanation

Y teacher two days were selected first street and second street

Remarks:

Multiple sets of input

 

Ideas: the k turn into a binary, how many number 1 on the list 

 

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <string>
 5 #include <math.h>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <queue>
 9 #include <set>
10 #include <stack>
11 #include <map>
12 #include <sstream>
13 const int INF=0x3f3f3f3f;
14 typedef long long LL;
15 const int mod=1e9+7;
16 const int maxn=2*1e6+10;
17 using namespace std;
18  
19 int main()
20 {
21     LL n;
22     while(~scanf("%lld",&n))
23     {
24         int day=0;
25         LL t;
26         while(n)
27         {
28             t=n%2;
29             if(t) day++;
30             n/=2;
31         }
32         printf("%d\n",day);
33     }
34     return 0;
35 }

 

 

 

 

 

 

 

 

K count Xiaoyang

Links: https://ac.nowcoder.com/acm/contest/3667/K
Source: Cattle-off network

Title Description

A troubled inner martial arts, self-reliance throughout all sects, sects order to identify the door disciple, gave everyone a token, which has a magical place,
the disciples in the martial art is not necessarily the same token,
following his identification rules:
everyone token is a string of numbers, if two people have similar place tokens that have the same number, it would belong to the same martial art, in particular,
if two people not have the same number, but the two people and another person with the same numbers, then the three men belong to a martial art, there is now a task
, give you n tokens, so that you recognize how many sects
such as 
3
13579
2468
12
where the answer should be 1, because the first person and second person and a third person has a relationship at the same time

Enter a description:

A first input line t, the number (1 <= t <= 10 ) representing the data sets 
of the second input line of a n, n represents the block token (1 <= n <= 1000 )
following n rows, each row a number sequence , (1 <= len <= 1000)

Output Description:

There are t lines, each line a number, representing the number of this set of data martial art
Example 1

Entry

2
3
13579
2468
12
5
12
23
34
5
5678

Export

1
2

 

 

Each point as the number of operating figures disjoint-set

 

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <string>
 5 #include <math.h>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <stack>
 9 #include <queue>
10 #include <set>
11 #include <map>
12 #include <sstream>
13 const int INF=0x3f3f3f3f;
14 typedef long long LL;
15 const int mod=1e9+7;
16 const double PI = acos(-1);
17 #define Bug cout<<"---------------------"<<endl
18 const int maxn=1e5+10;
19 using namespace std;
20 
21 int fa[10];
22 
23 int find(int x)
24 {
25     while(x!=fa[x])
26         x=fa[x];
27     return x;
28 }
29 
30 int main()
31 {
32     int T;
33     scanf("%d",&T);
34     while(T--)
35     {
36         int n;
37         scanf("%d",&n);
38         char str[1005];
39         int vis[10]={0};
40         for(int i=0;i<10;i++)
41             fa[i]=i;
42         for(int i=1;i<=n;i++)
43         {
44             scanf("%s",str);
45             vis[str[0]-'0']=1;
46             int t=str[0]-'0';
47             for(int i=1;str[i];i++)
48             {
49                 vis[str[i]-'0']=1;;
50                 int x=find(t);
51                 int y=find(str[i]-'0');
52                 if(x!=y)
53                     fa[x]=y;
54             }
55         }
56         set<int> st;
57         for(int i=0;i<10;i++)
58         {
59             if(vis[i])
60                 st.insert(find(i));
61         }
62         printf("%d\n",st.size());
63     }
64     return 0;
65 }

 

 

 

 

 

 

-

Guess you like

Origin www.cnblogs.com/jiamian/p/12154535.html