锘??xml version="1.0" encoding="utf-8" standalone="yes"?> Cool J has recently become a businessman Mr. Jackson, and he has to make a lot of phone calls now. Today he has n calls planned. For each call we know the moment ti (in seconds since the start of the day) when it is scheduled to start and its duration di (in seconds). All ti are different. Mr. Jackson is a very important person, so he never dials anybody himself, all calls will be incoming. Mr. Jackson isn't Caesar and he can't do several things at once. If somebody calls him while he hasn't finished the previous conversation, Mr. Jackson puts the new call on hold in the queue. In this case immediately after the end of the current call Mr. Jackson takes the earliest incoming call from the queue and starts the conversation. If Mr. Jackson started the call at the second t, and the call continues for d seconds, then Mr. Jackson is busy at seconds t, t + 1, ..., t + d - 1, and he can start a new call at second t + d. Note that if Mr. Jackson is not busy talking when somebody calls, he can't put this call on hold. Mr. Jackson isn't Napoleon either, he likes to sleep. So sometimes he allows himself the luxury of ignoring a call, as if it never was scheduled. He can ignore at most k calls. Note that a call which comes while he is busy talking can be ignored as well. What is the maximum number of seconds Mr. Jackson can sleep today, assuming that he can choose an arbitrary continuous time segment from the current day (that is, with seconds from the 1-st to the 86400-th, inclusive) when he is not busy talking? Note that some calls can be continued or postponed to the next day or even later. However, the interval for sleep should be completely within the current day. The first input line contains a pair of integers n, k (0 ≤ k ≤ n ≤ 4000) separated by a space. Following n lines contain the description of calls for today. The description of each call is located on the single line and consists of two space-separated integers ti and di, (1 ≤ ti, di ≤ 86400). All ti are distinct, the calls are given in the order of strict increasing ti. Scheduled times of calls [ti, ti + di - 1] can arbitrarily intersect. Print a number from 0 to 86400, inclusive — the maximally possible number of seconds for Mr. Jackson to sleep today. In the first sample the most convenient way is to ignore the first two calls. In the second sample it is best to ignore the third call. In this case Mr. Jackson will have been speaking: Thus, the longest period of free time is from the 40001-th to the 79999-th second. DP錛涳紱錛?/p>
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n. The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero. When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that: Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved. The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tn, ti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces. Print the required maximum sum of the sculptures' attractiveness. In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 懈 3. 鏆村姏姹傝В鐨勩傘傘?/p>
灝辨槸絳夐棿闅斿彇鏁幫紝姹傚叾鍜屾渶澶у鹼紒錛侊紒 After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group. Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus. In the first test we can sort the children into four cars like this: There are other ways to sort the groups into four cars. 姘撮錛?涓漢鐨勫崟鐙?/p>
3鍜?鎼厤錛?/p>
2鍜?鎼厤銆?/p>
3鏈夊鐨勮瘽鍙兘鍗曠嫭浜嗐?/p>
2鍙互鍔犲叆1涓殑 "Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many participants will advance to the next round. The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 50) separated by a single space. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the score earned by the participant who got the i-th place. The given sequence is non-increasing (that is, for all i from 1 to n - 1 the following condition is fulfilled: ai ≥ ai + 1). Output the number of participants who advance to the next round. In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score. 寰堢畝鍗曠殑棰樼洰~~~~~ 3 2
30000 15000
40000 15000
50000 1500049999
5 1
1 20000
10000 10000
20000 20000
25000 10000
80000 6000039999
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int dp[4005][4005];
struct node
{
int s,d;
};
node a[4005];
int main()
{
int i,j,n,k,ans;
while(scanf("%d%d",&n,&k)!=EOF)
{
for(i=0;i<n;++i)
{
scanf("%d%d",&a[i].s,&a[i].d);
}
ans=0;
for(i=0;i<=n;++i)
{
for(j=0;j<=k;++j)
{
dp[i][j]=86401;
}
}
dp[0][0]=1;
for(i=0;i<n;++i)
{
for(j=0;j<=k;++j)
{
if(j!=k)
dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]);
if(dp[i][j]<a[i].s)
{
ans=max(ans,a[i].s-dp[i][j]);
dp[i+1][j]=min(dp[i+1][j],a[i].s+a[i].d);
}
else
{
dp[i+1][j]=min(dp[i+1][j],dp[i][j]+a[i].d);
}
}
}
for(j=0;j<=k;++j)
{
ans=max(ans,86401-dp[n][j]);
}
printf("%d\n",ans);
}
return 0;
}
鏂囩珷鏉ユ簮:http://www.cnblogs.com/kuangbin/archive/2012/03/05/2380629.html
]]>
8
1 2 -3 4 -5 5 2 314
6
1 -2 3 -4 5 -69
6
1 2 3 4 5 621
#include<stdio.h>
int aa[20110];
int main()
{
int n;
int res;
int sum;
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)
scanf("%d",&aa[i]);
res=-200000000;
for(int i=1;i<=n/3;i++)
{
if(n%i!=0)continue;
if(n/i<3)continue;
for(int j=1;j<=i;j++)
{
sum=0;
for(int k=j;k<=n;k+=i)
sum+=aa[k];
if(sum>res) res=sum;
}
}
printf("%d\n",res);
}
return 0;
}
鏂囩珷鏉ユ簮:http://www.cnblogs.com/kuangbin/archive/2012/03/05/2380627.html
]]>5
1 2 4 3 34
8
2 3 4 4 2 1 3 15
#include<stdio.h>
int aa[5];
int main()
{
int n;
int t;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<5;i++)aa[i]=0;
while(n--)
{
scanf("%d",&t);
aa[t]++;
}
int res=0;
res+=aa[4];
if(aa[1]==aa[3])
{
res+=aa[1];
aa[1]=0;
aa[3]=0;
if(aa[2]%2==0)
{
res+=aa[2]/2;
}
else
{
res=res+aa[2]/2+1;
}
}
else if(aa[1]<aa[3])
{
res+=aa[1];
aa[3]-=aa[1];
aa[1]=0;
res+=aa[3];
if(aa[2]%2==0)
{
res+=aa[2]/2;
}
else
{
res=res+aa[2]/2+1;
}
}
else
{
res+=aa[3];
aa[1]-=aa[3];
aa[3]=0;
if(aa[2]%2==0)
{
res+=aa[2]/2;
}
else
{
res=res+aa[2]/2+1;
aa[1]-=2;
}
if(aa[1]>=1)
{
if(aa[1]%4==0) res+=aa[1]/4;
else
res=res+aa[1]/4+1;
}
}
printf("%d\n",res);
}
return 0;
}
鏂囩珷鏉ユ簮:http://www.cnblogs.com/kuangbin/archive/2012/03/05/2380624.html
]]>8 5
10 9 8 7 7 7 5 56
4 2
0 0 0 00
#include<stdio.h>
int mm[120];
int main()
{
int n,k;
while(scanf("%d%d",&n,&k)!=EOF)
{
for(int i=1;i<=n;i++)
scanf("%d",&mm[i]);
int res=k;
if(mm[k]>0)
{
for(int i=k+1;i<=n;i++)
{
if(mm[i]<mm[k])break;
res++;
}
}
else
{
res--;
for(int i=k-1;i>=1;i--)
{
if(mm[i]>0) break;
res--;
}
}
printf("%d\n",res);
}
return 0;
}
鏂囩珷鏉ユ簮:http://www.cnblogs.com/kuangbin/archive/2012/03/05/2380621.html
]]>
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0

#include<stdio.h>
long long dp[31][31];
void init()
{
dp[0][0]=1;
for(int i=1;i<31;i++)
{
dp[i][0]=1;
for(int j=1;j<i;j++)
dp[i][j]=dp[i-1][j]+dp[i][j-1];
dp[i][i]=dp[i][i-1];
}
}
int main()
{
int N;
init();
while(scanf("%d",&N),N)
{
printf("%I64d\n",dp[N][N]);
}
return 0;
}
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
int a[50];
int main()
{
int N,res,j;
int iCase=0;
while(scanf("%d",&N),N)
{
iCase++;
for(int i=0;i<N;i++)
{
scanf("%d",&a[i]);
}
for(j=0;j<N-1;j++)
{
if(a[j]!=a[j+1])break;
}
if(j>=N-1)
{
printf("Case %d: 0 iterations\n",iCase);
continue;
}
for(res=1;res<=1000;res++)
{
a[N]=a[0];
for(int i=0;i<N;i++)
{
a[i]=abs(a[i]-a[i+1]);
}
for(j=0;j<N-1;j++)
{
if(a[j]!=a[j+1])break;
}
if(j>=N-1)break;
}
if(res<=1000)printf("Case %d: %d iterations\n",iCase,res);
else printf("Case %d: not attained\n",iCase);
}
return 0;
}
| Time Limit: 1000 MS | Memory Limit: 65536 K |
| Total Submit: 97(31 users) | Total Accepted: 28(24 users) | Special Judge: No |
鎯沖繀澶у宸茬粡棰嗙暐浜嗗簵闀跨殑璋冪毊,鑷粠搴楅暱鐭ラ亾浜唙agaa涔嬪悗灝變竴鐩存矇榪鋒湡涓笉鑳借嚜鎷?鏁欎富鐪嬪埌鍚庡緢鏄激蹇冿紝鐜╃墿涓у織鍟?浜庢槸鏁欎富鏁欏簵闀夸簡涓涓獀agaa鐨勬柊鐢ㄦ硶,璧勬簮鎼滅儲鍔熻兘銆傝緭鍏ヤ竴浜涘叧閿瘝鍚庡彲浠ユ悳绱㈠嚭鐩稿叧鍏變韓鐨勫ソ璧勬簮錛屽簵闀垮緱鐭ュ悗鍙堟槸嬈e枩鑻ョ媯銆傚悓鏃?鏁欎富鍙堝彂鏄庝竴涓父鎴忥紝鏄笂嬈$殑鍗囩駭鐗?榪欐緇欏嚭涓浜涚敱瀛楁瘝鍜屾暟瀛楃殑鐜╁叿鐨勫悓鏃訛紝鍏抽敭瀛椾笉鍐嶆槸vagaa浜嗭紝闇瑕佽嚜宸辯粰鍑?鐪嬫渶鍚庤兘緇勬垚澶氬皯涓叧閿瓧銆?/p>
姣忚杈撳叆涓涓瓧絎︿覆鐢卞皬鍐欏瓧姣嶅拰鏁板瓧緇勬垚錛屾瘡涓瓧絎︿唬琛ㄤ竴涓帺鍏? 绱ф帴鐫杈撳叆涓涓叧閿瓧錛屽悓鏍風敱瀛楁瘝鍜屾暟瀛楃粍緇勬垚錛屽瓧絎︿覆闀垮害0<n<=10000錛屽叧閿瓧闀垮害0<m<=200
澶勭悊鍒版枃浠剁粨鏉?/p>
杈撳嚭鑳藉緇勬垚鍏抽敭瀛楃殑鏁伴噺
鎸夌収鏍蜂緥杈撳嚭鏍煎紡杈撳嚭騫舵崲琛?
vagaadsfaagav ga
asgvasdfzxcades dea
Case 1: 2
Case 2: 1
#include<stdio.h>
#include<string.h>
int tt[40],count[40];
char str[10010];
int main()
{
int len,m;
int iCase=0;
while(scanf("%s",&str)!=EOF)
{
iCase++;
len=strlen(str);
memset(tt,0,sizeof(tt));
memset(count,0,sizeof(count));
for(int i=0;i<len;i++)
{
if(str[i]>='0'&&str[i]<='9')
{
m=str[i]-'0'+0;
tt[m]++;
}
else
{
m=str[i]-'a'+10;
tt[m]++;
}
}
scanf("%s",&str);
len=strlen(str);
for(int i=0;i<len;i++)
{
if(str[i]>='0'&&str[i]<='9')
{
m=str[i]-'0'+0;
count[m]++;
}
else
{
m=str[i]-'a'+10;
count[m]++;
}
}
int res=10000;
for(int i=0;i<=9+26;i++)
{
if(count[i]>0)
{
int tmp=tt[i]/count[i];
if(tmp<res) res=tmp;
}
}
printf("Case %d: %d\n",iCase,res);
}
return 0;
}
| Time Limit: 1000 MS | Memory Limit: 65535 K |
| Total Submit: 29(11 users) | Total Accepted: 9(9 users) | Special Judge: No |
2
#include<stdio.h>
#include<string.h>
const int MAXN=100020;
int flag[MAXN];
int dp[MAXN];
int main()
{
int L,s,t,n;
int a;
while(scanf("%d%d%d%d",&L,&s,&t,&n)!=EOF)
{
memset(flag,0,sizeof(flag));
memset(dp,-1,sizeof(dp));//鍒濆鍖栵紝-1涓轟笉鑳藉埌杈劇殑
//dp[i]琛ㄧず鍒板簳 i 鐐歸渶瑕佺粡榪囩殑鏈灝戠煶瀛愭暟錛?1琛ㄧず涓嶈兘鍒拌揪
for(int i=0;i<n;i++)
{
scanf("%d",&a);
flag[a]=1;//鏈夌煶瀛愪負1錛屽惁鍒欎負0
}
dp[0]=0;
for(int i=s;i<=L+t-1;i++)
{
for(int j=i-t;j<=i-s;j++)// j 鐐硅煩鍒?i 鐐?
{
if(j>=0&&dp[j]!=-1)//j 鐐硅兘澶熻煩鍒?
{
if(dp[i]==-1)dp[i]=dp[j]+flag[i]; //絎竴嬈?鐩?鎺?緇?鍊?
else if(dp[i]>dp[j]+flag[i]) dp[i]=dp[j]+flag[i];//鎵懼皬鐨勫?
}
}
}
int res=10000;
for(int i=L;i<=L+t-1;i++)//L 鍒?L+t-1 涓渶灝忕殑闈?-1 鍊?
{
if(dp[i]!=-1&&dp[i]<res) res=dp[i];
}
printf("%d\n",res);
}
return 0;
}
2011騫達紝鎬繪劅瑙夎嚜宸卞緱鍒頒簡寰堝錛屼篃澶卞幓浜嗗緢澶氾紝涔熺暀涓嬩笉灝界殑閬楁喚銆備粛璁板緱2011騫村埌鏉ョ殑鏃跺欙紝鎴戣嚜宸卞鑷繁璇磋繖涓騫村皢浼氭槸鎴戝叧閿殑涓騫達紝緇欒嚜宸卞畾涓嬩簡寰堝鐩爣~~~~榪欎簺鐩爣鍙兘璇存槸澶ц嚧瀹炵幇浜嗗惂錛屼篃寰堝閬楁喚錛?/span>
涓轟簡榪庢帴2012騫達紝鎬繪劅瑙夎嚜宸卞簲璇ュ啓鐐逛笢瑗匡紝鏉ユ葷粨鑷繁鐨?011錛岃鍒掍笅2012.浣嗘槸涓鐩存娊涓嶅嚭鏃墮棿鏉ュ啓銆傜瓑鏈夋椂闂翠簡鍐嶅啓涓綃囨潵鎬葷粨2011鍚э紒
浜虹敓搴旇澶勪簬涓嶆柇鐨勫鏂楀綋涓紒2012騫達紝鎴戣鍙栧緱鎴愬姛錛?012騫達紝鎴戜竴瀹氫細鍋氬緱鏇村ソ錛?/span>
鍔犳補錛?/span>
————————————————————————————————————by kuangbin
榪欓鍋氫簡濂戒箙浜嗭紝瀛︿範浜嗙綉涓婄殑瑙f硶鍚庤嚜宸卞啓鍑烘潵浜嗐?/p>
灝辨槸鏋氫婦12*60鍒嗛挓錛岀湅涓鍒嗛挓鍐呮湁澶氬皯縐掓槸happytime錛屼竴鍒嗛挓鍐呰В涓変釜涓嶇瓑寮忓緱鍒板尯闂淬?/p>
鍏蜂綋鐪嬩唬鐮併?/p>
浠g爜鏈夋敞閲婂緢璇︾粏鐨勩?/p>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct qujian
{
double l,r;
};
double D;
qujian solve(double a,double b)//瑙f柟紼?D<=a*x+b<=360-D ,騫朵笖鍜?[0,60] 鍙栦氦闆?/span>
{
qujian p;
if(a>0)
{
p.l=(D-b)/a;
p.r=(360-D-b)/a;
}
else
{
p.l=(360-D-b)/a;
p.r=(D-b)/a;
}
if(p.l<0)p.l=0;
if(p.r>60)p.r=60;
if(p.l>=p.r) p.l=p.r=0;
return p;
}
qujian jiao(qujian a,qujian b)
{
qujian p;
p.l=max(a.l,b.l);
p.r=min(a.r,b.r);
if(p.l>=p.r) p.l=p.r=0;
return p;
}
/*
hh=30*h+m/2+s/120;
mm=6*m+s/10;
ss=6*s;
D<=|hh-mm|<=360-D;
D<=|hh-ss|<=360-D;
D<=|mm-ss|<=360-D;
hh-mm=
*/
double happytime(int h,int m)//璁$畻 h 鏃訛紝m 鍒?婊¤凍棰樻剰鐨勭鏁?/span>
{
double a,b;
qujian s[3][2];
qujian s1;
//瑙f柟紼?D<=|hh-mm|<=360-D
//hh=30*h+m/2+s/120;
//mm=6*m+s/10;
a=1.0/120-0.1;
b=30*h+m/2.0-6*m;
s[0][0]=solve(a,b);
s[0][1]=solve(-a,-b);
//瑙f柟紼? D<=|hh-ss|<=360-D
//hh=30*h+m/2+s/120;
//ss=6*s;
a=1.0/120-6.0;
b=30*h+m/2.0;
s[1][0]=solve(a,b);
s[1][1]=solve(-a,-b);
//瑙f柟紼? D<=|mm-ss|<=360-D
//mm=6*m+s/10;
//ss=6*s;
a=0.1-6;
b=6*m;
s[2][0]=solve(a,b);
s[2][1]=solve(-a,-b);
double res=0;
//鍏釜鍖洪棿錛岄変笁涓彇浜ら泦銆?br /> //鍥犱負緇濆鍊肩殑寮忓瓙寰楀埌鐨勪袱涓尯闂磋騫訛紝鑰屼笁涓笉鍚岃〃杈懼紡鐨勫尯闂磋浜わ紝鏁呰繖鏍峰仛銆?
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
for(int k=0;k<2;k++)
{
s1=jiao(jiao(s[0][i],s[1][j]),s[2][k]);
res+=s1.r-s1.l;
}
return res;
}
int main()
{
while(scanf("%lf",&D))
{
if(D==-1) break;
double res=0;
int h,m;
for(h=0;h<12;h++)
{
for(m=0;m<60;m++)
{
res+=happytime(h,m);
}
}
printf("%.3lf\n",res*100.0/(60*60*12));
}
return 0;
}