NOIP 2016 普及组 Solution (T1-T3)

第一题

直接贴Code:

 1 #include <cstdio>
 2 int min(int a,int b)
 3 {
 4     return a<b?a:b;
 5 }
 6 using namespace std;
 7 int main()
 8 {
 9     int n,a1,a2,b1,b2,c1,c2,ans;
10     scanf("%d%d%d%d%d%d%d",&n,&a1,&a2,&b1,&b2,&c1,&c2);
11     printf("%d\n",min(((int)(n-1)/c1+1)*c2,min((((int)(n-1)/a1+1)*a2),((int)(n-1)/b1+1)*b2)));
12 }
View Code

 第二题


正确姿势:枚举年份判断

暴力姿势:一个个枚举

暴力AC Code:

 1 #include <cstdio>
 2 #include <iostream>
 3 using namespace std;
 4 char s[10],e[10];
 5 int sy,sm,sd,ey,em,ed,ans,y,m,d;
 6 inline bool h(int y,int m,int d)
 7 {
 8     if ((y/1000!=d%10)||(y/100%10!=d/10)||(y/10%10!=m%10)||(y%10!=m/10))return 0;
 9     else return 1;
10 }
11 int main()
12 {
13     scanf("%s%s",s,e);
14     sy=(s[0]-'0')*1000+(s[1]-'0')*100+(s[2]-'0')*10+s[3]-'0';
15     ey=(e[0]-'0')*1000+(e[1]-'0')*100+(e[2]-'0')*10+e[3]-'0';
16     sm=(s[4]-'0')*10+s[5]-'0';
17     em=(e[4]-'0')*10+e[5]-'0';
18     sd=(s[6]-'0')*10+s[7]-'0';
19     ed=(e[6]-'0')*10+e[7]-'0';
20     y=sy;m=sm;d=sd;
21     while (1)
22     {
23         if (y>ey||(y==ey&&m==em&&d>ed)||(y==ey&&m>em))break;
24         if (m==12&&d==31&&y==1321)ans++;
25         if (m==12&&d==31)y++,m=d=1;
26         
27         if (h(y,m,d))ans++;
28         bool r=0;
29         if ((y%4==0&&y%100!=0)||y%400==0)r=1;
30         if (m==1||m==3||m==5||m==7||m==8||m==10||m==12)
31         {
32             if (d<31)d++;
33                 else if (d==31&&m!=12)m++,d=1;
34         }else
35         if (m==4||m==6||m==9||m==11)
36         {
37             if(d<30)d++;
38             else if (d==30)m++,d=1;
39         }else
40         if (m==2)
41         {
42             if (r&&d<29)d++;else if (r&&d==29)m++,d=1;
43             if (!r&&d<28)d++;else if (!r&&d==28)m++,d=1;
44         }
45     }
46     printf("%d",ans);
47 }
View Code

 第三题

队列模拟(队列要开大点QAQ,DEBUG了半天...)

 

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define ll long long
 5 inline void read(ll &k)
 6 {
 7     ll f=1;k=0;char c=getchar();
 8     while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
 9     while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
10     k*=f;
11 }
12 
13 const int maxn=1e5+10;
14 ll n,tmp,tot,t[maxn*10],tt,k[maxn*10],cnt[maxn*3],k1,last=1,ans;
15 bool v[maxn];
16 
17 int main()
18 {
19     read(n);
20     while(n--)
21     {
22         read(tt);read(tmp);
23         while(tmp--)
24         {
25             read(k1);
26             t[++tot]=tt;cnt[k1]++;k[tot]=k1;
27             if ((cnt[k1]==1)&&(!v[k1]))ans++;
28         }
29         while (t[last]+86400<=tt)
30         {
31             cnt[k[last]]--;
32             if (!cnt[k[last]])ans--;
33             last++;
34         }
35         printf("%lld\n",ans);
36     }
37 }
View Code

 

posted @ 2017-08-13 07:51  Michael_Zhuang  阅读(136)  评论(0编辑  收藏  举报