链接:https://ac.nowcoder.com/acm/contest/11166/
来源:牛客网

A Alice and Bob

暴力seg

  首先(0,0)是一个必败点,通过它可以筛选出这组的必胜点,进而找到下一组必败点。

  结论:如果一个石子堆是i 另一堆石子至多存在一种数量满足后手胜(对应的这个j是最小的)

  复杂度(o(n*n*log(N)))

暴力代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 bitset<5005> seg[5005];
 4 int t;
 5 void init()
 6 {
 7     for(int i=0;i<=5000;i++)
 8         for(int j=0;j<=5000;j++)
 9         {
10             if(!seg[i][j])
11             {
12                 for(int s=1;i+s<=5000;s++)
13                     for(int k=0;j+s*k<=5000;k++)
14                         seg[i+s][j+s*k]=1;
15                 for(int s=1;s+j<=5000;s++)
16                     for(int k=0;i+s*k<=5000;k++)
17                         seg[i+s*k][s+j]=1;
18             }
19         }
20 }
21 int main()
22 {
23     ios::sync_with_stdio(0);
24     cin.tie(0);
25     init();
26     cin>>t;
27     while(t--)
28     {
29         int n,m;
30         cin>>n>>m;
31         puts(seg[n][m]?"Alice":"Bob");
32     }
33     return 0;
34 }

 

B Ball Dropping

模拟题

直接上代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 long double y,r,a,b,h;
 4 int main()
 5 {
 6     cin>>r>>a>>b>>h;
 7     if(b>2*r)
 8         puts("Drop");
 9     else
10     {
11         puts("Stuck");
12         long double t=b*h/(a-b);
13         y=2*r*sqrt(a*a/4+(t+h)*(t+h))/a;
14         printf("%.10Lf\n",y-t);
15     }
16     return 0;
17 }

 

D Determine the Photo Position

 

签到题

 1 #include <bits/stdc++.h>
 2 int n,m,ans;
 3 char s[2005][2005];
 4 int main()
 5 {
 6     scanf("%d%d",&n,&m);
 7     for(int i=0;i<n;i++){
 8         scanf("%s",s[i]);
 9         int num = 0;
10         for(int j=0;j<n;j++){
11             if(s[i][j]=='0') num++;
12             else num = 0;
13             if(num>=m) ans++;
14         }
15     }
16     printf("%d\n",ans);
17     return 0;
18 }

 

F Find 3-friendly Integers

 

数位dp+规律

 

通过数位dp思路,很容易推出n>=100时满足条件(实际上n>=89),这样只需要对n<89的部分暴力即可

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 long long t,l,r;
 4 bool check(long long x)
 5 {
 6     if(x<10)
 7     {
 8         if(x%3)return false;
 9         return true;
10     }
11     if(x%3==0||(x%10)%3==0||(x/10)%3==0)return true;
12     return false;
13 }
14 int main()
15 {
16     ios::sync_with_stdio(0);
17     cin.tie(0);
18     cin>>t;
19     while(t--)
20     {
21         long long ans=0;
22         cin>>l>>r;
23         if(l>=89)
24             ans=r-l+1;
25         else if(r<89)
26         {
27             for(int i=l;i<=r;i++)
28                 if(check(i))ans++;
29         }
30         else
31         {
32             ans=r-89+1;
33             for(int i=l;i<89;i++)
34                 if(check(i))ans++;
35         }
36         cout<<ans<<'\n';
37     }
38 }