银联高校极客挑战赛 初赛 第二场

开场几十分钟后才开始打的,实验室居然锁门了。。。

A. 码队GO

左上、右下角为(1,1)、(x,y)的矩阵的大小,dp处理

然后一个裸的二分答案

sum=

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <cmath>
 4 #include <cstring>
 5 #include <string>
 6 #include <algorithm>
 7 #include <iostream>
 8 using namespace std;
 9 #define ll long long
10 
11 const double eps=1e-8;
12 const ll inf=1e9;
13 const ll mod=1e9+7;
14 const int maxn=3e2+10;
15 
16 char str[maxn][maxn];
17 int temp[2][maxn][maxn],f[maxn][maxn],a[maxn][maxn];
18 
19 int main()
20 {
21     int t,n,m,l,r,mid,i,j;
22     bool vis;
23     scanf("%d",&t);
24     while (t--)
25     {
26         scanf("%d%d",&n,&m);
27         for (i=1;i<=n;i++)
28             scanf("%s",str[i]+1);
29         for (i=1;i<=n;i++)
30             for (j=1;j<=m;j++)
31                 a[i][j]=a[i][j-1]+(str[i][j]=='.');
32         for (j=1;j<=m;j++)
33             for (i=1;i<=n;i++)
34                 f[i][j]=f[i-1][j]+a[i][j];
35         l=1,r=min(n,m);
36         while (l<=r)
37         {
38             mid=(l+r)>>1;
39             vis=0;
40             for (i=mid;i<=n;i++)
41                 for (j=mid;j<=m;j++)
42                     if (f[i][j]-f[i-mid][j]-f[i][j-mid]+f[i-mid][j-mid]==mid*mid)
43                         vis=1;
44             if (vis)
45                 l=mid+1;
46             else
47                 r=mid-1;
48         }
49         printf("%d\n",r*r);
50 /*
51         r=0;
52         for (i=1;i<=n;i++)
53             for (j=1;j<=n-i+1;j++)
54                 for (k=1;k<=n-i+1;k++)
55                 {
56                     f[i][j][k]=f[i-1][j+1][k]+f[i-1][j][k+1]-f[i-2][j+1][k+1]+(str[j][k]=='.')+(str[j+i-1][k+i-1]=='.');
57                     if (f[i][j][k]==i*i)
58                         r=max(r,i);
59                 }
60 */
61     }
62     return 0;
63 }

B. 码队弟弟的求和问题

n,m为独立的两部分,相乘即可

接下来是整除分块,对于同一块,余数是一个等差数列

update:

我只是找到了规律,

应该培养推公式的能力。。。

n%i 的数学式子

gcd 的数学式子

  1 #include <cstdio>
  2 #include <cstdlib>
  3 #include <cmath>
  4 #include <cstring>
  5 #include <string>
  6 #include <algorithm>
  7 #include <iostream>
  8 using namespace std;
  9 #define ll long long
 10 
 11 const double eps=1e-8;
 12 const ll inf=1e9;
 13 const ll mod=1e9+7;
 14 const int maxn=1e5+10;
 15 
 16 ///sum(sum(i*j*(n mod i)(m mod j)) mod 1e9+7
 17 ///1e9
 18 
 19 int maxv=1e5;
 20 
 21 //int zhi[maxn];
 22 bool vis[maxn];
 23 
 24 ll work(ll n)
 25 {
 26     ll l,r,sum=0,a0,b0,q,g,xx,yy,zz;
 27     for (l=1;l<=n;l=r+1)
 28     {
 29         r=n/(n/l);
 30         if (l==r)
 31             sum+=n%l*l;
 32         else
 33         {
 34             ///a0=l,b0,q,g
 35             a0=l;
 36             b0=n%l;
 37             q=n/l;
 38             g=r-l+1;
 39 
 40             ///0^2+1^2+...
 41             (sum+=a0*b0%mod*g)%=mod;
 42             if (g&1)
 43                 (sum+=b0*g%mod*((g-1)/2))%=mod;
 44             else
 45                 (sum+=b0*(g/2)%mod*(g-1))%=mod;
 46             if (g&1)
 47                 (sum-=a0*q%mod*g%mod*((g-1)/2))%=mod;
 48             else
 49                 (sum-=a0*q%mod*(g/2)%mod*(g-1))%=mod;
 50 
 51             xx=g-1;
 52             yy=g;
 53             zz=2*g-1;
 54             if (xx%2==0)
 55                 xx/=2;
 56             else if (yy%2==0)
 57                 yy/=2;
 58             else
 59                 zz/=2;
 60             if (xx%3==0)
 61                 xx/=3;
 62             else if (yy%3==0)
 63                 yy/=3;
 64             else
 65                 zz/=3;
 66             (sum-=q*xx%mod*yy%mod*zz)%=mod;
 67 //                q*(g-1)*g*(2*g-1)/6
 68             ///sum+=a0*b0*g + b0*g*(g-1)/2 - a0*q*g*(g-1)/2 - q*(g-1)*g*(2*g-1)/6;
 69 
 70 //            sum+=a0*g-q*g*(g-1)/2;
 71         }
 72 //        printf("%lld %lld\n",l,r);
 73     }
 74     return sum;
 75 }
 76 
 77 int main()
 78 {
 79     /*
 80     ///n 最小的质因数
 81     for (i=2;i<=maxv;i++)
 82     {
 83         if (!vis[i])
 84         {
 85             zhi[++cnt_zhi]=i;
 86             for (j)
 87         }
 88     }
 89     */
 90 
 91     ll n,m,i;
 92     ///two parts
 93     scanf("%lld%lld",&n,&m);
 94     printf("%lld",(work(n)*work(m)%mod+mod)%mod);
 95     return 0;
 96 }
 97 /*
 98 1 1
 99 2 2
100 3 3
101 4 4
102 5 5
103 6 6
104 7 7
105 1000000000 1000000000
106 */

C. 异世界幻想

菜鸡不会推公式,只能找规律

打表

update:

我觉得没多少人能按照题解的方法写出来。。。

我感觉更多的是xxx,甚至是yyy。

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <cmath>
 4 #include <cstring>
 5 #include <string>
 6 #include <algorithm>
 7 #include <iostream>
 8 using namespace std;
 9 #define ll long long
10 #include <set>
11 
12 const double eps=1e-8;
13 const ll inf=1e9;
14 const ll mod=1e9+7;
15 const int maxn=15;
16 
17 int n,a[maxn],hap[maxn],link[maxn],siz_n;
18 ll sum=0;
19 set<int>se;
20 
21 void judge(int step)
22 {
23     int x,y;
24     if (step==n-1)
25     {
26         x=*se.begin();
27         se.erase(se.begin());
28         y=*se.begin();
29         se.erase(se.begin());
30         link[x]++,link[y]++;
31         for (x=1;x<=n;x++)
32             if (link[x]==1)
33                 sum++;
34         return;
35     }
36     x=*se.begin();
37     se.erase(se.begin());
38     y=a[step];
39     link[x]++,link[y]++;
40     hap[y]--;
41     if (hap[y]==0)
42         se.insert(y);
43     judge(step+1);
44 }
45 
46 void work(int step)
47 {
48     int i;
49     if (step==n-1)
50     {
51         se.clear();
52         memset(hap,0,siz_n);
53         memset(link,0,siz_n);
54         for (i=1;i<=n;i++)
55             hap[a[i]]++;
56         for (i=1;i<=n;i++)
57             if (hap[i]==0)
58                 se.insert(i);
59         judge(1);
60         return;
61     }
62     for (i=1;i<=n;i++)
63     {
64         a[step]=i;
65         work(step+1);
66     }
67 }
68 
69 int main()
70 {
71     for (n=2;n<=10;n++)
72     {
73         siz_n=4*(n+1);
74         sum=0;
75         work(1);
76         printf("n=%d sum=%lld\n",n,sum);
77     }
78     return 0;
79 }
80 /*
81 n=2 sum=2
82 n=3 sum=6
83 n=4 sum=36
84 n=5 sum=320
85 n=6 sum=3750
86 n=7 sum=54432
87 n=8 sum=941192
88 n=9 sum=18874368
89 
90 n * (n-1)^(n-2)
91 */

代码

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <cmath>
 4 #include <cstring>
 5 #include <string>
 6 #include <algorithm>
 7 #include <iostream>
 8 using namespace std;
 9 #define ll long long
10 
11 const double eps=1e-8;
12 const ll inf=1e9;
13 const ll mod=998244353;
14 const int maxn=1e5+10;
15 
16 ll mul(ll a,ll b)
17 {
18     ll y=1;
19     while (b)
20     {
21         if (b&1)
22             y=y*a%mod;
23         a=a*a%mod;
24         b>>=1;
25     }
26     return y;
27 }
28 
29 int main()
30 {
31     ll n;
32     scanf("%lld",&n);
33     if (n==1)
34     {
35         printf("1");
36         return 0;
37     }
38 
39     printf("%lld",n*mul(n-1,n-2)%mod);
40     return 0;
41 }
42 /*
43 n=2 sum=2
44 n=3 sum=6
45 n=4 sum=36
46 n=5 sum=320
47 n=6 sum=3750
48 n=7 sum=54432
49 n=8 sum=941192
50 n=9 sum=18874368
51 
52 n * (n-1)^(n-2)
53 */

猜你喜欢

转载自www.cnblogs.com/cmyg/p/11221780.html