锘??xml version="1.0" encoding="utf-8" standalone="yes"?> y is divisible by 4, and y is not divisible by 100 unless it is divisible by 400. An year y, 0 < y < 1582 is a leap year if and only if
]]>
]]>
涓や釜浜虹埇灞憋紝鏃跺埢瑕佷繚璇佸湪鍚屼竴姘村鉤闈笂錛岀洿鍒頒袱浜轟簰鎹綅緗傞棶璧拌繃鐨勬渶鐭窛紱匯備袱鐐歸棿璺濈瀹氫箟涓轟袱鐐歸棿鐨剏杞寸粷瀵瑰煎樊銆?br>緇欏姏鏉′歡錛氶櫎浜?jiǎn)棣枮涓ょ傄?guī)瘡涓偣鐨剏鍧愭爣鍧囦笉鐩稿悓
瑙f硶錛?br>DP錛熸潃楦$敤鐗涘垁錛屾病蹇呰錛?br>璐績(jī)錛?br>棣栧厛鏄庣‘錛屼笉鑳借蛋鍥炲ご璺紝榪欓噷鐨勫洖澶磋礬鎸囧畬鍏ㄩ鍥炲埌涓婁釜姝ラ鎵鍦ㄧ殑鐐癸紝鏄劇劧錛岃繖鏍風(fēng)殑璧版硶鏄棤鎰忎箟鐨勩?br>璁劇疆涓や釜鎸囬拡錛宲1鎸囧悜澶達(dá)紝p2鎸囧悜灝撅紝寰幆鑷充袱涓寚閽堥噸鍙犮備笅闈㈠叿浣撳垎鍥涚鎯呭喌璁ㄨ錛?br>1銆佸鏋測(cè)p1+1>yp1涓攜p2-1>yp2錛岃繖縐嶆儏鍐典笅褰撶劧灞卞嘲楂樼殑甯姪灞卞嘲浣庣殑瓚婅繃浣庣殑灞卞嘲
2銆佸鏋測(cè)p1+1>yp1涓攜p2-1<yp2錛岃繖縐嶆儏鍐靛張瑕佸垎涓ょ鎯呭喌錛?br> 2.1 濡傛灉(p1,p1+1)榪欐涓婂潯閫氳繃灞閮ㄥ洖閫鑳藉璁﹑2搴﹁繃榪欎釜灞辮胺錛屾樉鐒惰繖鏍峰氨鏄痯2--
2.2 鍚﹀垯p1蹇呴』鍥為鑷充笂涓嫄鐐癸紝璇曞浘鑾峰緱鏇翠綆鐨勯珮搴︼紝榪欐牱灝辨槸p1--
3銆佸鏋測(cè)p1+1<yp1涓攜p2-1>yp2錛屼笌涓婄鎯呭喌綾諱技錛屼笉鍔犺禈榪般?br>4銆佸鏋測(cè)p1+1<yp1涓攜p2-1<yp2錛岃繖縐嶆儏鍐典笉搴旇鏄甯告儏鍐典笅搴旇鍑虹幇鐨勶紝鍥犺鏄鍒版煇涓緢娣辯殑灞辮胺鍚庝笂鍧℃鍥為褰㈡垚鐨勶紝榪欐椂鍊欏簲璇ョ戶緇悗閫錛屼互瀵繪眰鏇翠綆鐐廣?br>
浠g爜閲屽啓鐨勫緢娓呮錛屽ぇ瀹剁湅浠g爜鍚э細(xì)
# include <cstdio>
2
using namespace std;
3
# define min(a,b) ((a)<(b)?(a):(b))
4
# define max(a,b) ((a)>(b)?(a):(b))
5
int p[1001][2],n,p1,p2,ans,last;
6
int main()
7

{
8
int test;
9
scanf("%d",&test);
10
while(test--)
11
{
12
scanf("%d",&n);
13
for(int i=0;i<n;i++)
14
scanf("%d %d",&p[i][0],&p[i][1]);
15
p1=0,p2=n-1,ans=0;
16
last=p[0][1];
17
while(p2>p1)
18
{
19
if(p[p2-1][1]>p[p2][1]&&p[p1+1][1]>p[p1][1])
20
{
21
ans+=2*(min(p[p2-1][1],p[p1+1][1])-last);
22
last=min(p[p2-1][1],p[p1+1][1]);
23
if(p[p2-1][1]==last) p2--;
24
if(p[p1+1][1]==last) p1++;
25
}
26
else if(p[p2-1][1]<p[p2][1]&&p[p1+1][1]>p[p1][1])
27
{
28
ans+=2*(last-max(p[p2-1][1],p[p1][1]));
29
last=max(p[p2-1][1],p[p1][1]);
30
if(last==p[p2-1][1]) p2--;
31
else p1--;
32
}
33
else if(p[p2-1][1]>p[p2][1]&&p[p1+1][1]<p[p1][1])
34
{
35
ans+=2*(last-max(p[p2][1],p[p1+1][1]));
36
last=max(p[p2][1],p[p1+1][1]);
37
if(last==p[p1+1][1]) p1++;
38
else p2++;
39
}
40
else
41
{
42
ans+=2*(min(p[p1][1],p[p2][1])-last);
43
last=min(p[p1][1],p[p2][1]);
44
if(last==p[p1][1]) p1--;
45
else p2++;
46
}
47
}
48
printf("%d\n",ans*2);
49
}
50
return 0;
51
}
52
]]>
璇寸櫧浜?jiǎn)灏辨槸璁〗帡鍏巻绯痪l熶腑鏌愬勾鏌愭湀鐨勭涓澶╂槸涓嶆槸鍛ㄤ竴銆佸懆鍏佸懆鏃ヤ互鍙?qiáng)鏌愹q存煇鏈堢殑鏈鍚庝竴澶╂槸涓嶆槸鍛ㄤ簲銆佸懆鍏佸懆鏃?br>鍏充簬鍏巻澶у鐭ラ亾鐨勫氨涓嶈浜?jiǎn)锛岃鍑犵偣澶у鍙兘涓嶇煡閬撶?br>1銆佸叧浜庨棸騫?br>An year y, y > 1582 and y ≠ 1700, is a leap year if and only if錛堟敞鎰忥紒1700綆楅棸騫達(dá)級(jí)
2銆佸叧浜庡叕鍘嗕腑鏈?1澶╃殑緙哄け
11 days are eliminated starting September 3, 1752 in order for people not to rewrite history
涓嬮潰灝辨槸甯歌鐨勫仛娉曚簡(jiǎn)銆傘?br>緇熻鎴鍒版瘡涓騫存湁澶氬皯澶╋紝鐒跺悗灝嗘墍鏈夌殑lucky month鍜実ood month閮芥壘鍑烘潵錛岄『搴忓瓨鏀懼湪鏁扮粍涓紝鏌ヨ鐨勬椂鍊欎簩鍒嗗噺涓涓嬪氨鍙互浜?jiǎn)~
浠g爜錛?br>
2 using namespace std;
3 int o[]={31,28,31,30,31,30,31,31,30,31,30,31},l[]={31,29,31,30,31,30,31,31,30,31,30,31};
4 int y[10001];
5 # include <vector>
6 # include <algorithm>
7 # define MON 730124
8 # define FRI 730121
9 # define SAT 730122
10 # define SUN 730123
11 vector<int> lucky,good;
12 int main()
13 {
14 //init
15 for(int i=1;i<12;i++)
16 o[i]+=o[i-1],l[i]+=l[i-1];
17 y[0]=0;
18 for(int i=1;i<10000;i++)
19 {
20 if(i<1582&&i%4==0||i>1582&&(i%4==0&&i%100!=0||i%400==0)||i==1700)
21 y[i]=y[i-1]+l[11];
22 else
23 y[i]=y[i-1]+o[11];
24 if(i==1752) y[i]-=11;
25 }
26 for(int i=1;i<10000;i++)
27 {
28
29 int *m;
30 if(i<1582&&i%4==0||i>1582&&(i%4==0&&i%100!=0||i%400==0)) m=l;
31 else m=o;
32 if(i==1752)
33 {
34 for(int j=8;j<12;j++) m[j]-=11;
35 }
36 if((y[i-1]+1-MON)%7==0||(y[i-1]+1-SAT)%7==0||(y[i-1]+1-SUN)%7==0) good.push_back(i*12+1);
37 if((y[i-1]+o[0]-FRI)%7==0||(y[i-1]+o[0]-SAT)%7==0||(y[i-1]+o[0]-SUN)%7==0) lucky.push_back(i*12+1);
38 for(int j=1;j<12;j++)
39 {
40 if((y[i-1]+1+m[j-1]-MON)%7==0||(y[i-1]+1+m[j-1]-SAT)%7==0||(y[i-1]+1+m[j-1]-SUN)%7==0) good.push_back(i*12+j+1);
41 if((y[i-1]+m[j]-FRI)%7==0||(y[i-1]+m[j]-SAT)%7==0||(y[i-1]+m[j]-SUN)%7==0) lucky.push_back(i*12+j+1);
42 }
43 if(i==1752)
44 {
45 for(int j=8;j<12;j++) m[j]+=11;
46 }
47 }
48 int n;
49 cin>>n;
50 while(n--)
51 {
52 int y1,m1,y2,m2;
53 cin>>y1>>m1>>y2>>m2;
54 cout<<upper_bound(lucky.begin(),lucky.end(),y2*12+m2)-lower_bound(lucky.begin(),lucky.end(),y1*12+m1)<<" "<<upper_bound(good.begin(),good.end(),y2*12+m2)-lower_bound(good.begin(),good.end(),y1*12+m1)<<endl;
55 }
56 //system("pause");
57 return 0;
58 }
59
]]>
榪欓鍋氱殑鏃跺欐湁鐐筃C錛岀珶鐒跺繕浜?jiǎn)鎺掑簭銆傘傛睏銆傘?br>
# include <iostream>
2
# include <vector>
3
# include <algorithm>
4
# define abs(a) ((a)>0?(a):-(a))
5
using namespace std;
6
int data[50],n;
7
void make(int limit)
8

{
9
int used=0,p=0,last=1;
10
vector<int> ans;
11
while(p<n&&10*used+(last-1)*4+abs(data[p]-last)*20<=limit)
12
p++;
13
while(p<n)
14
{
15
16
int up=(limit+20*data[p]+4-10*used)/24;
17
last=up;
18
ans.push_back(last);
19
p++;
20
while(p<n&&10*used+(last-1)*4+abs(data[p]-last)*20<=limit)
21
p++;
22
used++;
23
}
24
cout<<ans.size();
25
for(int i=0;i<ans.size();i++)
26
cout<<" "<<ans[i];
27
cout<<endl;
28
}
29
bool chk(int limit)
30

{
31
int used=0,p=0,last=1;
32
while(p<n&&10*used+(last-1)*4+abs(data[p]-last)*20<=limit)
33
p++;
34
while(p<n)
35
{
36
37
if(10*used+(data[p]-1)*4>limit) return false;
38
int up=(limit+20*data[p]+4-10*used)/24;
39
//if(up>31) up=31;
40
last=up;
41
p++;
42
while(p<n&&10*used+(last-1)*4+abs(data[p]-last)*20<=limit)
43
p++;
44
used++;
45
46
}
47
return true;
48
}
49
int main()
50

{
51
while(true)
52
{
53
int s=0,e=-1;
54
cin>>n;
55
if(!n) break;
56
for(int i=0;i<n;i++)
57
{
58
cin>>data[i];
59
e=((data[i]-1)*20>e?(data[i]-1)*20:e);
60
}
61
sort(data,data+n);
62
// int *p=unique(data,data+n);
63
// n=p-data;
64
while(s<=e)
65
{
66
int mid=(s+e)>>1;
67
if(chk(mid))
68
e=mid-1;
69
else
70
s=mid+1;
71
}
72
cout<<s<<endl;
73
make(s);
74
}
75
return 0;
76
}
77
78
]]>