2017.10.25水题大作战题解

 

 

 

rank:

 

 

T1P1615 西游记公司

https://www.luogu.org/problemnew/show/P1615

scanf直接秒

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #define LL long long 
 6 using namespace std;
 7 inline LL read()
 8 {
 9     char c=getchar();LL x=0,f=1;
10     while(c<'0'||c>'9')    {if(c=='-')    f=-1;c=getchar();}
11     while(c>='0'&&c<='9')    x=x*10+c-48,c=getchar();return x*f;
12 }
13 int main()
14 {
15     LL a,b,c,d,e,f,n;
16     scanf("%lld:%lld:%lld%lld:%lld:%lld%lld",&a,&b,&c,&d,&e,&f,&n);
17     printf("%lld",n*(f-c+60*(e-b)+3600*(d-a)));
18     return 0;
19 }
View Code

T2P1838 三子棋I

https://www.luogu.org/problemnew/show/P1838

判断好每一种情况,不要忘了平局

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #define LL  long long 
 6 using namespace std;
 7 const int MAXN=201;
 8 inline int read()
 9 {
10     char c=getchar();int flag=1,x=0;
11     while(c<'0'||c>'9')    {if(c=='-')    flag=-1;c=getchar();}
12     while(c>='0'&&c<='9')    x=(x*10+c-48),c=getchar();    return x*flag;
13 }
14 int a[MAXN][MAXN];
15 char s[MAXN];
16 int hang[MAXN];
17 int lie[MAXN];
18 int hang2[MAXN];
19 int lie2[MAXN];
20 int main()
21 {
22     int n=3;
23     scanf("%s",s+1);
24     int now=1;
25     for(int i=1;i<=strlen(s+1);i++)
26     {
27         int p=(int)s[i]-48;
28         if(p%3!=0)
29         {
30             a[p/3+1][p%3]=now;
31             if(now==1)    hang[p/3+1]++,    lie[p%3]++;
32             else    hang2[p/+1]++,    lie2[p%3]++;
33         }
34         else
35         {
36             a[p/3][3]=now;
37             if(now==1)    hang[p/3]++,    lie[3]++;
38             else        hang2[p/3]++,    lie2[3]++;
39         }
40         if(now==1)    now=0;else now=1;
41     }
42     for(int i=1;i<=3;i++)
43         if(hang[i]==3||lie[i]==3)
44         {        printf("xiaoa wins.");    return 0;    }
45     if((a[1][1]==1&&a[2][2]==1&&a[3][3]==1)||(a[1][3]==1&&a[2][2]==1&&a[3][1]==1))
46     {    printf("xiaoa wins.");    return 0;    }
47     for(int i=1;i<=3;i++)
48         if(hang2[i]==3||lie2[i]==3)
49         {    printf("uim wins.");    return 0;    }
50     if((a[1][1]==0&&a[2][2]==0&&a[3][3]==0)||(a[1][3]==0&&a[2][2]==0&&a[3][1]==0))
51     {        printf("uim wins.");        return 0;    }
52     printf("drew.");
53     return 0;
54 }
View Code

T3P1319 压缩技术

https://www.luogu.org/problemnew/show/P1319

根据题意模拟即可

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #define LL  long long 
 6 using namespace std;
 7 const int MAXN=201;
 8 inline int read()
 9 {
10     char c=getchar();int flag=1,x=0;
11     while(c<'0'||c>'9')    {if(c=='-')    flag=-1;c=getchar();}
12     while(c>='0'&&c<='9')    x=(x*10+c-48),c=getchar();    return x*flag;
13 }
14 int n;
15 int main()
16 {
17     n=read();
18     int now=0;
19     int how=1;//zero 
20     int p;
21     while(cin>>p)
22     {
23         for(int i=1;i<=p;i++)
24         {
25             if(how==1)    printf("0");
26             else         printf("1");
27             now++;
28             if(now==n)    printf("\n"),now=0;
29         }
30         if(how==1)    how=0;
31         else how=1;
32     }
33     return 0;
34 }
View Code

T4P2077 红绿灯

https://www.luogu.org/problemnew/show/P2077

模拟汽车的行走路线,注意在经过红绿灯的时候取模

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #define LL  long long 
 6 using namespace std;
 7 const int MAXN=200001;
 8 inline int read()
 9 {
10     char c=getchar();int flag=1,x=0;
11     while(c<'0'||c>'9')    {if(c=='-')    flag=-1;c=getchar();}
12     while(c>='0'&&c<='9')    x=(x*10+c-48),c=getchar();    return x*flag;
13 }
14 int n,m;
15 int dis[MAXN];
16 int green[MAXN];
17 int red[MAXN];
18 int get(int pos,int val)
19 {
20     int now=val%(green[pos]+red[pos]);
21     if(now<=green[pos])    return 0;
22     return red[pos]-(now-green[pos]);
23 }
24 int main()
25 {
26     n=read(),m=read();
27     for(int i=1;i<=n-1;i++)    dis[i]=read();
28     for(int i=1;i<=n;i++)    red[i]=read();
29     for(int i=1;i<=n;i++)    green[i]=read();
30     int now=m;
31     for(int i=1;i<=n;i++)
32     {
33         now=now+get(i,now);
34         printf("%d\n",now);
35         now+=dis[i];
36     }
37     return 0;
38 }
View Code

T5P2043 质因子分解

https://www.luogu.org/problemnew/show/P2043

枚举1-n,依次进行分解

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #define LL  long long 
 6 using namespace std;
 7 const LL MAXN=200001;
 8 inline LL read()
 9 {
10     char c=getchar();LL flag=1,x=0;
11     while(c<'0'||c>'9')    {if(c=='-')    flag=-1;c=getchar();}
12     while(c>='0'&&c<='9')    x=(x*10+c-48),c=getchar();    return x*flag;
13 }
14 LL n;
15 LL vis[MAXN];
16 LL prime[MAXN];
17 LL tot=0;
18 LL ans[MAXN];
19 int main()
20 {
21     n=read();
22     vis[1]=1;
23     for(LL i=1;i<=10000;i++)
24     {
25         if(vis[i]==0)
26         {
27             prime[++tot]=i;
28             for(LL j=i;j<=15000;j+=i)
29                 vis[j]=1;
30         }    
31     }
32 //    for(LL i=1;i<=tot;i++)
33     //    cout<<prime[i]<<" ";
34     for(LL i=1;i<=n;i++)
35     {
36         LL p=i;
37         for(LL j=1;j<=tot;j++)
38             while(p%prime[j]==0&&p!=1)
39                 ans[j]++,p=p/prime[j];
40     }
41     for(LL i=1;i<=tot;i++)
42         if(ans[i]!=0)
43             printf("%lld %lld\n",prime[i],ans[i]);
44     return 0;
45 }
View Code

T6P1737 旷野大计算

https://www.luogu.org/problemnew/show/P1737

 

posted @ 2017-10-26 07:44  自为风月马前卒  阅读(131)  评论(0编辑  收藏  举报

Contact with me