2014年北京師範大學新生程式設計競賽網路賽

畫船聽雨發表於2014-12-27

比賽連結:http://acm.bnu.edu.cn/v3/contest_show.php?cid=5727

手速不夠。。。簡直了啊

A:大神們說打表找規律,然後就可以得到了。

<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
#define mod 1000000007



const int maxn = 1000010;

char str[maxn];


using namespace std;
int dp[maxn];

struct node
{
    int a, b;
}f[maxn];

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n, k;
        cin >>n>>k;
        if(n%2)
        {
            if((k-1)%4 < 2) puts("B");
            else puts("A");
        }
        else
        {
            if(k%2) puts("F");
            else if(k%4 == 0) puts("A");
            else puts("B");
        }
    }
}</span>

B:大水題,(n-1)/n,分數要化簡到最簡式。

<span style="font-size:18px;">#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
#define mod 1000000007



const int maxn = 210;



using namespace std;

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        LL n;
        scanf("%lld",&n);
        LL m = (n-1LL);
        LL t = __gcd(n, m);
        cout<<m/t<<"/"<<n/t<<endl;
    }
}</span>
C:比賽的時候猜了一下沒敢交。。。後來才發現是對的啊。。。

什麼都不加的話先手必勝,加了的話會構成環,如果是奇數環的話從第一個開始取先手必勝,偶數的環的話,先把環拆開,然後先手再取最大的可以必勝。總之,先手必勝。

<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);




const int maxn = 210;

using namespace std;

int main()
{
    int T;
    cin >>T;
    while(T--)
    {
        int n, m;
        int x, y;
        cin >>n>>m;
        for(int i = 0; i < m; i++) scanf("%d %d",&x, &y);
        puts("Bill will lose HAHA");
    }
    return 0;
}
</span>

D:矩陣加速遞推,水題做的太慢到這裡沒時間了啊。。sad

f(x)代表發育期;

g(x)代表更年期;

h(x)代表天數;

f(x) = y*g(x-1)+h(x-1)*p;

g(x) = x*f(x-1)+z*g(x-1);

h(x) = h(x-1)+1;

從:f(x-1)    g(x-1)  h(x-1)  1  到  f(x) g(x) h(x) 1

關係矩陣:

0 y p 0

x z 0 0

0 0 1 1

0 0 0 1

<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);




const int maxn = 210;

using namespace std;

struct matrix
{
    LL f[10][10];
};


matrix mul(matrix a, matrix b, int n)
{
    matrix c;
    memset(c.f, 0, sizeof(c.f));
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            for(int k = 0; k < n; k++) c.f[i][j] += a.f[i][k]*b.f[k][j];
            c.f[i][j];
        }
    }
    return c;
}

matrix pow_mod(matrix a, LL b, int n)
{

    matrix s;
    memset(s.f, 0 , sizeof(s.f));
    for(int i = 0; i < n; i++) s.f[i][i] = 1LL;
    while(b)
    {
        if(b&1) s = mul(s, a, n);
        a = mul(a, a, n);
        b >>= 1;
    }
    return s;
}

matrix Add(matrix a,matrix b, int n)
{
    matrix c;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            c.f[i][j] = a.f[i][j]+b.f[i][j];
            c.f[i][j];
        }
    }
    return c;
}


int main()
{
   int T;
   cin >>T;
    while(T--)
    {
        LL x, y, z, p, n;
        cin >>x>>y>>z>>p>>n;
        matrix c;
        memset(c.f, 0 ,sizeof(c.f));
        c.f[0][0] = 0;
        c.f[0][1] = y;
        c.f[0][2] = p;
        c.f[0][3] = 0;

        c.f[1][0] = x;
        c.f[1][1] = z;
        c.f[1][2] = 0;
        c.f[1][3] = 0;

        c.f[2][0] = 0;
        c.f[2][1] = 0;
        c.f[2][2] = 1;
        c.f[2][3] = 1;


        c.f[3][0] = 0;
        c.f[3][1] = 0;
        c.f[3][2] = 0;
        c.f[3][3] = 1;


        matrix d = pow_mod(c, n, 4);
        LL sum = 0LL;

        sum += d.f[0][3];
        sum += d.f[1][3];

        printf(">>%lld\n",sum);
    }
    return 0;
}
</span>

E:就是一個活動排序,大水題。

<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
#define mod 1000000007



const int maxn = 210;



using namespace std;

typedef struct sss
{
    int start_time;
    int end_time;
} s;
bool operator <(s a, s b)
{
    return a.end_time < b.end_time;
}
int main()
{
    int T;
    cin >>T;
    int n;
    while(T--)
    {
        cin>>n;
        int timestart = 0;
        vector<s> a;
        while(n--)
        {
            s temp;
            cin>>temp.start_time>>temp.end_time;
            a.push_back(temp);
        }
        sort(a.begin(),a.end(),less<s>());
        int count = 0;
        for(vector<s>::iterator ite = a.begin(); ite != a.end(); ++ite)
        {
            if((*ite).start_time > timestart)
            {
                count++;
                timestart = (*ite).end_time;
            }
        }
        cout<<count<<endl;
        //a.clear();
    }
}</span>

F:讀懂題之後就是一個標準的01揹包了啊。

PS:程式碼寫了1234B好巧啊。

<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
#define mod 1000000007



const int maxn = 1000010;

char str[maxn];


using namespace std;
int dp[maxn];

struct node
{
    int a, b;
}f[maxn];

int main()
{
    int T;
    scanf("%d",&T);
    int Case = 1;
    while(T--)
    {
        int A, B, n;
        scanf("%d %d %d",&A, &B, &n);
        for(int i = 0; i < n; i++) scanf("%d",&f[i].a);
        for(int i = 0; i < n; i++) scanf("%d",&f[i].b);
        memset(dp, 0, sizeof(dp));
        for(int i = 0; i < n; i++)
        {
            for(int j = A; j >= 0; j--)
            {
                if(j-f[i].a < 0) break;
                dp[j] = max(dp[j], dp[j-f[i].a]+f[i].b);
            }
        }
        printf("Case #%d: ",Case++);
        if(dp[A] >= B) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
</span>

G:分大圓裡面,小圓裡面。分別推一下公式就可以了啊,小圓裡面我是先求交點又推的公式。

<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
#define mod 1000000007



const int maxn = 1000010;

char str[maxn];


using namespace std;


int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        LL n;
        cin >>n;
        if(!n)
        {
            cout<<2<<endl;
            continue;
        }
        if(n == 1)
        {
            cout<<4<<endl;
            continue;
        }
        LL y = 2*n;
        y += (n+1)*n/2+1;
        ///if(n == 2) y++;
        cout<<y<<endl;

    }
}</span>

H:一個水題,結果錯了好多遍啊。讀題不認真啊。sad。。。

注意:i為偶數時i只能和i-1匹配。

<span style="font-size:18px;">#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <time.h>
#include <map>
#include <set>
#define eps 1e-8
#define M 1000100
#define LL long long
//#define LL long long
#define INF 0x3f3f3f
#define PI 3.1415926535898
#define read() freopen("data1.in", "r", stdin)
#define write() freopen("data1.out", "w", stdout);
#define mod 1000000007



const int maxn = 1000010;

char str[maxn];


using namespace std;

bool judge(char x, char y)
{
    if(x == 'a' && y == 'b' || x == 'b' && y == 'a') return 1;
    if(x == 'c' && y == 'd' || x == 'd' && y == 'c') return 1;
    if(x == 'e' && y == 'f' || x == 'f' && y == 'e') return 1;
    if(x == 'g' && y == 'h' || x == 'h' && y == 'g') return 1;
    if(x == 'i' && y == 'j' || x == 'j' && y == 'i') return 1;
    if(x == 'k' && y == 'l' || x == 'l' && y == 'k') return 1;
    if(x == 'm' && y == 'n' || x == 'n' && y == 'm') return 1;
    if(x == 'o' && y == 'p' || x == 'p' && y == 'o') return 1;
    if(x == 'q' && y == 'r' || x == 'r' && y == 'q') return 1;
    if(x == 's' && y == 't' || x == 't' && y == 's') return 1;
    if(x == 'u' && y == 'v' || x == 'v' && y == 'u') return 1;
    if(x == 'w' && y == 'x' || x == 'x' && y == 'w') return 1;
    if(x == 'y' && y == 'z' || x == 'z' && y == 'y') return 1;
    return 0;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s",str);
        int len = strlen(str);
        char sx[maxn];
        int top = 0;
        for(int i = 0; i < len; i++)
        {
            if(!top)
            {
                sx[top++] = str[i];
                continue;
            }
            if(abs(str[i]-sx[top-1]) == 1 && judge(str[i], sx[top-1])) top--;
            else sx[top++] = str[i];
        }
        sx[top] = '\0';
        if(!top)
        {
            puts("sad!");
            continue;
        }
        puts(sx);
    }
}</span>


相關文章