Gym101522A Gym101522C Gym101522D

Posted Persistent.

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gym101522A Gym101522C Gym101522D相关的知识,希望对你有一定的参考价值。

Gym101522A

 

A

There are two popular formats for representing a date: day/month/year or month/day/year. For example, today can be represented as 15/8/2017 or 8/15/2017.

Sometimes (like on today), using one way or another should pose no confusion — it is immediately understood that the date is the 15th of August. On other days, however, the two representations may be interpreted as two different valid dates. For example, the 7th of August may be misinterpreted as the 8th of July, since both can be represented as 7/8/2017 (or 8/7/2017).

We say a date (D, M, Y) is ambiguous if D/M/Y and M/D/Y, when both interpreted in the day/month/year format, are different valid dates. For example, (7, 8, 2017) and (8, 7, 2017) are ambiguous, while (15, 8, 2017) and (10, 10, 2017) are not.

The total number of ambiguous dates in the Gregorian calendar system on any given year is equal to 12?×?11?=?132.

Now, suppose that in a hypothetical calendar system, there are M months, where the i-th month has D[i] days, numbered from 1 to D[i]. Assume that there are no leap years.

You are to carry out a calendar reform, by shuffling the array D[], and your target is to minimize the total number of ambiguous dates in a calendar year. Specifically, you want to find a permutation p[1],?p[2],?...,?p[M] of integers 1,?2,?...,?M, such that the new calendar system, where the i-th month has D[p[i]] days, has the minimal number of ambiguous dates. Output that minimal number.

Input

The first line of input consists of a single integer M, the number of months in the hypothetical calendar system.

The second line of input consists of M integers D[1],?D[2],?...,?D[M], the original number of days in the i-th month.

For all test cases, 1?≤?M?≤?1051?≤?D[i]?≤?105.

Output

Output a single integer, the minimal number of ambiguous dates after the calendar reform.

Example

Input
12
31 28 31 30 31 30 31 31 30 31 30 31
Output
132
Input
3
5 1 1
Output
0



代码:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<algorithm>
 5 using namespace std;
 6 typedef long long ll;
 7 const int N=1e5+10;
 8 int a[N];
 9 int main(){
10     int n;
11     ll ans;
12     while(~scanf("%d",&n)){
13         for(int i=1;i<=n;i++)
14             scanf("%d",&a[i]);
15         sort(a+1,a+1+n);
16         ans=0;
17         for(int i=1;i<=n;i++){
18             if(a[i]>n){if(n-i>0)ans+=n-i;}
19             if(a[i]<n){if(a[i]-i>0)ans+=a[i]-i;}
20             if(a[i]==n){if(n-i>0)ans+=n-i;}
21         }
22         ans*=2;
23         printf("%lld\n",ans);
24     }
25     return 0;
26 }

 

 

 

 

C

To boost contestants‘ performances in the 20th La Salle - Pui Ching Programming Challenge, the organizers have bought N robots to cheer for them. Each robot is supposed to display cheering slogans, letter by letter.

Unfortunately, due to some technical reasons, the display screen of each robot can only display one fixed character. Therefore, the organizers decided to arrange the robots in a row, thus forming a string of N letters (What a waste!). All letters are in uppercase.

The two hosting schools have abbreviated names LSC and PCMS, as we all know. Which of the two names appear (as a substring) in the string more often?

Input

The first and only line of input consists of a string with N uppercase letters.

For all test cases, N?≤?100.

Output

Let A be the number of occurrences of LSC in the given string.

Let B be the number of occurrences of PCMS in the given string.

If A?>?B, output LSC.

If A?<?B, output PCMS.

If A?=?B, output Tie.

Example

Input
GOLSC
Output
LSC
Input
PCMSISTHEBEST
Output
PCMS
Input
PCMSWILLNEVERBEATLSC
Output
Tie
Input
ADDOILEVERYONE
Output
Tie


代码:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<cmath>
 5 #include<algorithm>
 6 using namespace std;
 7 const int N=1e5+10;
 8 char s[N];
 9 int main(){
10     memset(s,0,sizeof(s));
11     while(~scanf("%s",s)){
12         int len=strlen(s);
13         int num1=0,num2=0;
14         for(int i=0;i<len;i++){
15             if(s[i]==L){
16                 if(s[i+1]==S&&s[i+2]==C&&i+2<len)num1++;
17             }
18             if(s[i]==P){
19                 if(s[i+1]==C&&s[i+2]==M&&s[i+3]==S&&i+3<len)num2++;
20             }
21         }
22         if(num1>num2)printf("LSC\n");
23         else if(num1<num2)printf("PCMS\n");
24         else printf("Tie\n");
25     }
26     return 0;
27 }

 

 

 

 

D

The Gregorian calendar is internationally the most widely used civil calendar. It is named after Pope Gregory XIII, who introduced it in October 1582.

In the Gregorian calendar, there are 28 days in February in a common year and 29days in February in a leap year. Year Y is a leap year if and only if Y is a multiple of 400, or Y is a multiple of 4 and is not a multiple of 100.

Percy is curious about the distribution of days of the week of his birthday in his life. By checking the calendar, he quickly finds that in the years between 1999 and 2017 (inclusive), his birthday (in case you do not know, 27 February) appears only twice on both Tuesday and Thursday, three times on each of the other days of the week.

Percy finds counting the distribution of some days in some consecutive years really cool, so he decides to invent a way to quickly count the distribution.

Within 15 minutes, he successfully invented a fast program to do the calculation for years between 1583 and 2?×?109, inclusive. His program can answer 5000 queries in 1second. However, he is not sure if the program works correctly, so he needs your help. Your task is simple, write your own program to do the calculation, so that Percy can check his program‘s correctness by comparing the outputs of different queries with your program.

In this problem, please assume the definition of leap years mentioned above is true for all years between 1583 and 2?×?109, inclusive.

Input

The first line consists of a single integer, Q, denotes the number of queries. (1?≤?Q?≤?5000)

In the next Q lines, each describes a single query. The queries are in the format S E M D, which means you have to calculate the distribution of days of the week for the D-th day of the M-th month for all years between S and E, inclusive. (1583?≤?S?≤?E?≤?2?×?109, the days given are one of the 366 valid days)

Output

Output Q lines, each answers a query given.

In each line output 7 integers, the frequencies of days of the weeks in this order: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday.

The order of answers should follow the order of queries given.

Example

Input
1
1999 2017 2 27
Output
3 3 2 3 2 3 3
Input
2
2017 2017 8 15
2017 2021 2 29
Output
0 0 1 0 0 0 0
0 0 0 0 0 0 1
Input
4
3141 5926 5 3
5897 9323 8 4
2718 2818 2 8
2222 2222 2 22
Output
404 391 403 390 404 396 398
488 488 497 481 497 480 496
15 14 14 15 14 15 14
0 0 0 0 0 1 0

 

 

 

这个题根本就没有什么技术含量,但是我写T了,

基姆拉尔森计算公式不好用,慎用。

贴一下超时代码和正解代码:

正解(不是我写的,我的T了,不想改了)

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<stack>
 7 #include<map>
 8 #include<vector>
 9 #include<set>
10 #include<queue>
11 using namespace std;
12 typedef long long ll;
13 const int MAXN=1e5+10;
14 const double mod=1e16+7;
15 int isr(int n)
16 {
17     if(n%4==0&&n%100!=0||n%400==0)return 1;
18     else return 0;
19 }
20 int da[810][15][35];
21 
22 void init()
23 {
24     int k[15],l=6;
25     k[1]=31,k[2]=28,k[3]=31,k[4]=30,k[5]=31,k[6]=30;
26     k[7]=31,k[8]=31,k[9]=30,k[10]=31,k[11]=30,k[12]=31;
27     memset(da,0,sizeof(da));
28     for(int i=0;i<=399;i++){
29         for(int j=1;j<=12;j++){
30             if(j==2)
31             for(int t=1;t<=k[j]+isr(i);t++){
32                 if(l+1==8)l=0;
33                 da[i][j][t]=++l,da[i+400][j][t]=l;
34             }
35             else
36             for(int t=1;t<=k[j];t++){
37                 if(l+1==8)l=0;
38                 da[i][j][t]=++l,da[i+400][j][t]=l;
39             }
40         }
41     }
42 }
43 
44 int main()
45 {
46     int q,y1,y2,m,d,t;
47     ll s[10];
48     cin>>q;
49     init();
50     while(q--){
51         memset(s,0,sizeof(s));
52         scanf("%d%d%d%d",&y1,&y2,&m,&d);
53         if(y2-y1>=400){
54             t=(y2-y1)/400;
55             for(int i=1;i<=400;i++)
56             s[da[i][m][d]]+=t;
57         }
58         y1%=400,y2%=400;
59         if(y1>y2) y2+=400;
60         for(int i=y1;i<=y2;i++){
61             s[da[i][m][d]]++;
62         }
63         for(int i=1;i<=7;i++)
64         cout<<s[i]<<" ";
65         cout<<endl;
66     }
67 }

 

贴一下我的超时垃圾代码:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<cmath>
 5 #include<math.h>
 6 using namespace std;
 7 int CaculateWeekDay(int y,int m, int d){
 8     if(m==1||m==2){
 9         m+=12;
10         y--;
11     }
12     int iWeek=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;//基姆拉尔森计算公式根据日期判断星期几
13     if(m==2&&d==29) return iWeek+15;
14     return iWeek+1;
15 }
16 int b[30];
17 int year1=0,year2=0,month=0,day=0;
18 void isbb(){
19     memset(b,0,sizeof(b));
20     for(int i=1;i<=400;i++){
21         int temp=CaculateWeekDay(i,month,day);
22         b[temp]++;
23     }
24 }
25 int main(){
26     int a[10];
27     int t;
28     while(~scanf("%d",&t)){
29         while(t--){
30             scanf("%d%d%d%d",&year1,&year2,&month,&day);
31             memset(a,0,sizeof(a));
32             isbb();
33             if((year2-year1)/400){
34                 int x=(year2-year1)/400;
35                 if(month==2&&day==29){
36                     int j=1;
37                     for(int i=15;i<=22;i++)
38                         a[j++]=b[i];
39                 }
40                 else{
41                     for(int i=1;i<=7;i++)
42                         a[i]=b[i];
43                 }
44                 for(int i=1;i<=7;i++)
45                     a[i]*=x;
46                 year1%=400;
47                 if(year2%400<year1)year2=year2%400+400;
48                 else year2%=400;
49                 for(int i=year1;i<=year2;i++){
50                     if(month==2&&day==29){
51                         if(i%400==0){
52                             int temp=CaculateWeekDay(i,month,day);
53                             a[temp-15]++;
54                         }
55                     }
56                     else{
57                         int temp=CaculateWeekDay(i,month,day);
58                         a[temp]++;
59                     }
60                 }
61             }
62             else{
63                  for(int i=year1;i<=year2;i++){
64                     int temp=CaculateWeekDay(i,month,day);
65                     a[temp]++;
66                 }
67             }
68         }
69         cout<<a[7];
70         for(int i=1;i<=6;i++)
71             cout<<" "<<a[i];
72         cout<<endl;
73     }
74     return 0;
75 }

 

 

心累。。。






以上是关于Gym101522A Gym101522C Gym101522D的主要内容,如果未能解决你的问题,请参考以下文章

OpenAI Gym 入门与提高 Gym环境构建与最简单的RL agent

强化学习 平台 openAI 的 gym 安装 (Ubuntu环境下如何安装Python的gym模块)

openai/gym 中各种环境(Env)的参数解释

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

gym 搭建 RL 环境

强化学习笔记:Gym入门--从安装到第一个完整的代码示例