冬训 day2

模拟枚举。。。

A - New Year and Buggy Bot(http://codeforces.com/problemset/problem/908/B

 暴力枚举即可,但是直接手动暴力会非常繁琐,所以用到了STL,next_permutation(a,a+4),这个函数便是对a内元素进行全排列。

 1 #include<bits/stdc++.h>
 2 #define N 100000
 3 #define ll long long
 4 using namespace std;
 5 int a[4]; 
 6 char ma[70][70],s[110];
 7 int main()
 8 {
 9     int n,m,x,y,mx,my,ans=0;
10     cin>>n>>m;
11     for(int i=0;i<n;++i) cin>>ma[i];
12     for(int i=0;i<n;++i)
13       for(int j=0;j<m;++j)
14          if(ma[i][j]=='S') x=i,y=j;
15     getchar();
16     cin>>s;
17     for(int i=0;i<4;++i) a[i]=i+48;
18     do
19     {
20         mx=x;my=y;
21         int g=0;
22         for(int i=0;i<strlen(s);++i)
23         {
24             if(s[i]==a[0]) mx--;
25             else if(s[i]==a[1]) mx++;
26             else if(s[i]==a[2]) my--;
27             else my++;
28             if(mx<0||my<0||mx>=n||my>=m) break;
29             if(ma[mx][my]=='#') break;
30             if(ma[mx][my]=='E') 
31             { 
32                g=1;break;
33             }
34         }
35         ans+=g;
36     }while(next_permutation(a,a+4));
37     cout<<ans;
38 }
View Code

B - Local Extrema

 遍历水。

C - The Artful Expedient

 按理说是不会T的,原因在于傻子n?后来改成存储出现过的数就好了,而不必一边一边去扫描。。平时常用的东西为什么会突然想不起来用呢…………

D - Quasi-palindrome

 去掉后导0判断回文就好了啊。。。似乎就是手残?少打一个等号,wa了五发。。。

E - Generous Kefa

 根据题意,看哪种气球给每个人都发了还有剩的,就gg。

F - Five-In-a-Row

 这个题没什么难度,搜索即可,只是代码量稍微大点。注意处理好边界条件。然而这个题还是有手残,两个地方的j写成i,怪我咯

G - An abandoned sentiment from past

 能不能补进去生成非单调递增的序列。。考虑最好的情况时能不能实现就OK,即把子序列降序加进去,再判断就OK了

 1 #include<bits/stdc++.h>
 2 #define N 100000
 3 #define ll long long
 4 using namespace std;
 5 int a[200],b[200],vis[200];
 6 int main()
 7 {
 8     int n,k;
 9     cin>>n>>k;
10     memset(a,0,sizeof(a));
11     memset(b,0,sizeof(b));
12     memset(vis,0,sizeof(vis));
13     for(int i=1;i<=n;++i) scanf("%d",&a[i]);
14     for(int i=1;i<=k;++i) scanf("%d",&b[i]);
15     sort(b+1,b+n+1);
16     int hh=n,zha=0;
17     for(int i=1;i<=n;++i)
18     {
19         if(!a[i])
20         {
21             a[i]=b[hh--];
22         }
23     }
24     for(int i=1;i<=n;++i)
25     {
26         if((a[i]<=a[i-1]&&i!=1)||(a[i]>=a[i+1]&&i!=n)) 
27         {
28             zha=1;break;
29         }
30     }
31     if(zha) printf("YES
");
32     else printf("NO
"); 
33     return 0;
34 }
View Code

H - Score

无脑模拟。。

I - Online Judge

 主要问题在读入吧我觉得。。好好用strcat,想用string来着,但是东西都忘了就没用。。。读入的时候就顺便存一个不带空格,换行符,制表符的,先直接比较,再比较去掉空白符的,即可。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<cstdlib>
 5 using namespace std;
 6 char s1[5005],s2[5005],ss1[5005],ss2[5005];
 7 char temp[5005];
 8 void read(char s[],char ss[])
 9 {
10     gets(temp);
11     while(strcmp(temp,"START"))
12      gets(temp);
13     while(gets(temp))
14     {
15         if(strcmp(temp,"END")==0) break;
16         if(strlen(temp)) strcat(s,temp);
17         strcat(s,"
");
18     }
19     int t=0;
20     for(int i=0;i<strlen(s);++i)
21     {
22         if(s[i]!=' '&&s[i]!='	'&&s[i]!='
')
23           ss[t++]=s[i];
24     }
25     ss[t]='';
26 }
27 int main()
28 {
29     int n;
30     scanf("%d",&n);
31     while(n--)
32     {
33         s1[0]='';s2[0]='';
34         read(s1,ss1);read(s2,ss2);
35         if(strcmp(s1,s2)==0) printf("Accepted
");
36         else 
37         {
38             if(strcmp(ss1,ss2)==0) printf("Presentation Error
");
39             else printf("Wrong Answer
");
40         }
41     }
42 }
View Code

J - WERTYU

再次死在手残加眼残?把'老人家给忘了真的怪我。。。不过用字符串似乎是个好东西。。

K - Maximum Product

 O(n2)算法即可,但是不明白为什么我的maxa设成-N就炸了。。。留着这个问题放几天。。。

L - NPY and arithmetic progression

 这个题是个脑洞吧。。所有大于三的都可以直接分成公差为0的数列。。所以只有1,2,3,2,3,4,1,2,3,4三种情况,来一遍爆搜,每一次都判断是否满足,满足退出即可。这个题我WA五发的原因是把Yes打成了YES!!!!!!!!!

 1 #include<bits/stdc++.h>
 2 #define N 100000
 3 #define ll long long
 4 using namespace std;
 5 bool check(int x[])
 6 {
 7     for(int i=1;i<=4;++i)
 8     {
 9         if(x[i]==0||x[i]>=3) continue;
10         else return false;
11     } 
12     return true;
13 }
14 int main()
15 {
16      int t,a[5],b[5];
17      cin>>t;
18      while(t--)
19      {
20           int flag=0;
21           for(int i=1;i<=4;++i) 
22          {
23              scanf("%d",&a[i]);
24          }
25         if(check(a)) 
26             flag=1;
27          else
28          {
29            for(int i=0;i<=2;++i)//1 2 3 
30              for(int j=0;j<=2;++j)//2 3 4
31               for(int k=0;k<=2;++k)//1 2 3 4
32            {
33             b[1]=a[1]-i-k;
34             b[2]=a[2]-i-j-k;
35             b[3]=a[3]-i-j-k;
36             b[4]=a[4]-j-k;
37             if(check(b))
38            {
39             flag=1;break;
40            }
41         }
42     }
43         if(flag) printf("Yes
");
44         else printf("No
");
45      }
46 }
View Code

M - Visit

 来回各种走肯定会晕。。。为了达到最优,所以只能转向一次。枚举每个点转向即可。

 1 #include <iostream>
 2 #include<stdio.h>
 3 #include<algorithm>
 4 using namespace std;
 5 int n,T,a[2005];
 6 int main()
 7 {
 8     int s,q,p,ma,x,y;
 9     while(scanf("%d %d",&n,&T)!=EOF)
10     {
11         a[0]=0;//加一个0,这样便于后面的操作 
12         for(int i=1; i<=n; i++)
13             scanf("%d",&a[i]);
14         sort(a,a+n+1);//从小到大排序,
15         s=lower_bound(a,a+n+1,0)-a;//找到点0
16         ma=0;
17         for(q=s;q>=0;q--)//q是往左
18         {
19             for(p=s;p<=n;p++)//p是往右
20             {
21                 x=-a[q],y=a[p];
22                 if(2*x+y<=T&&p-q>ma) ma=p-q;//左右
23                 if(2*y+x<=T&&p-q>ma) ma=p-q;//右左
24             }
25         }
26         cout<<ma<<endl;
27     }
28     return 0;
29 }
View Code

N - Coat of Anticubism

 脑洞题。。想一个大三角形就行了。

O - Island Puzzle

 相对位置不变。。不要手残。

P - Polyline

 没看见题上说只有三个点。。。枚举所有情况即可。

手残手残手残。

原文地址:https://www.cnblogs.com/TYH-TYH/p/8313995.html