CCPC-Wannafly Winter Camp Day8 (Div2, onsite)

D.吉良吉影的奇妙计划

Code:zz

Thinking:zz kk

暴力搜索,打表

//#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<math.h>
#include<cmath>
#include<time.h>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
#include<numeric>
#include<stack>
#include<bitset>
#include<unordered_map>
const int maxn = 0x3f3f3f3f;
const double EI = 2.71828182845904523536028747135266249775724709369995957496696762772407663035354594571382178525166427;
const double PI = 3.141592653589793238462643383279;
using namespace std;
long long p = 998244353;
long long c[30] = {1,2,6,14,38,100,268,726,1974,5404,14852,40972,113388,314632,
875112,2439014,6810102,19045612,53341428,149589348};
int main(void)
{
    //ios::sync_with_stdio(false);
    int n,i,j,k;
    long long ans;
    while(~scanf("%d",&n))
    {
        printf("%lld\n",c[n - 1]);
    }
    return 0;
}
View Code

 

G 穗乃果的考试

Code:kk

Thinking:kk

由题目所给的式子会发现其实就是让我们数每个1出现在几个子矩阵中,式子简单搞搞就好了。

#include<bits/stdc++.h>
#define CLR(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=2010;
ll p=998244353;
int mp[maxn][maxn];
ll n,m,ans;
int main(){
    cin>>n>>m;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            scanf("%1d",&mp[i][j]);
            if(mp[i][j]){
                ans=(ans+i*(n-i+1)*j*(m-j+1)%p)%p;
            }
        }
    }
    cout<<ans<<endl;
}
View Code

J 去音乐会

Code:pai爷

Thinking:pai爷

#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define ll long long
using namespace std;
int T;
int gcd(int a,int b)
{
    return b==0?a:gcd(b,a%b);
}
void exgcd(int a,int b,int &x,int &y)
{
    if(b==0){x=1;y=0;return;}
    exgcd(b,a%b,x,y);
    ll t=x;
    x=y;y=t-a/b*y;
}

int main()
{
    scanf("%d",&T);
    while(T--)
    {
        ll m,n,l,sum=0,ans=0;
        int a,b,c,d,aa,bb,cc,t,x,y;
        scanf("%d%d%d%d%lld",&a,&b,&c,&d,&n);
        for(int A=a+1;A<=b;A++)
        {
            for(int B=c+1;B<=d;B++)
            {
                aa=-b;bb=d;cc=A-B;
                t=gcd(aa,bb);
                if(cc%t!=0) continue;
                aa/=t;bb/=t;cc/=t;
                exgcd(aa,bb,x,y);
                if(bb<0) bb=-bb;
                x=((1ll*cc*x)%bb+bb)%bb;
                if(n-A<0) sum=0;
                else if((n-A)/b-x<0) sum=0;
                else sum=((n-A)/b-x)/bb+1;
                ans+=sum;
            }
        }
        printf("%lld\n",ans);
    }
}
View Code

 

posted @ 2019-01-29 22:17  光芒万丈小太阳  阅读(362)  评论(0编辑  收藏  举报