1. 程式人生 > >I am a slow walker, but I never walk backwards!

I am a slow walker, but I never walk backwards!

比賽連結: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>

相關推薦

I am a slow walker, but I never walk backwards!

比賽連結:http://acm.bnu.edu.cn/v3/contest_show.php?cid=5727 手速不夠。。。簡直了啊 A:大神們說打表找規律,然後就可以得到了。 <span style="font-size:18px;">#include &

【凡事預則立,不預則廢】I am a little little girl in a big big world,But that is not a big big thing if you leave me alone.

I am a little little girl in a big big world,But that is not a big big thing if you leave me alone.

有一個字元陣列的內容為:"student a am i", 將陣列的內容改為"i am a student"

有一個字元陣列的內容為:"student a am i", 將陣列的內容改為"i am a student" 要求:  不能使用庫函式 只能開闢有限個空間(空間個數和字串的長度無關) eg: student a am i  i ma a tneduts  i

將字元陣列:“student a am i”,改為:“i am a student”

問題:有一個字元陣列的內容為:"student a am i",請你將陣列的內容改為"i am a student".            要求:不能使用庫函式。只能開闢有限個空間(空間個數和字

有一個字元陣列的內容為:"student a am i", 請你將陣列的內容改為"i am a stude

#include <stdio.h> #include <stdlib.h> #include <string.h> void reverse_string(char*start, char *end){  while (start < e

C語言實現有一個字元陣列的內容為:"student a am i",請你將陣列的內容改為"i am a student"。

//有一個字元陣列的內容為:"student a am i",請你將陣列的內容改為"i am a student"。    要求:不能使用庫函式。               只能開闢有限個空間(空間個數和字串的長度無關)。   解題思路:               

"student a am i"變為'' i am a student"

有一個字元陣列的內容為:“student a am i”, 請你將陣列的內容改為"i am a student". 要求: 不能使用庫函式。 只能開闢有限個空間(空間個數和字串的長度無關)。 student a am i i ma a tneduts i am

有一個字元陣列的內容為:"student a am i", 請你將陣列的內容改為"i am a student".

有一個字元陣列的內容為:"student a am i",  請你將陣列的內容改為"i am a student".  要求:  不能使用庫函式。  只能開闢有限個空間(空間個數和字串的長度無關)。 

有一個字元陣列的內容為:"student a am i", 請你將陣列的內容改為"i am a student".

//有一個字元陣列的內容為:"student a am i", // 請你將陣列的內容改為"i am a student". #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> void

Ask HN: Ideas for an APP,I am a Data Science Analyst and I know Django very well

I would like to see an app that shows the most used memes on a social media platform so that I know which memes not to use.

Yes, I coded a Semaphore and no, I am not an OS developer.

You are sitting in an 8th standard Mathematics classroom reading about Pythagorean Triplets, you are mugging up the Pythagoras Theorem. The famous equation

I am a coder

    被公司調到新網路部門研究SDN,專案涉及到一些虛擬網路的概念。初次接觸VLAN和VXLAN技術,特整理資料學習下。 VLAN ·概況      VLAN (Virtual Local Area

將輸入的字串反序列印。例如輸入“I am a student.”輸出“student. a am I”。

public class Solution {     public String ReverseSentence(String str) {         if(str.trim().length

輸入一個英文句子,翻轉句子中的單詞,要求單詞內的字元順序不變。 如:I am a student. 轉換成 student. a am I

輸入一個英文句子,翻轉句子中的單詞,要求單詞內的字元順序不變。 如:I am a student. 轉換成 student. a am I  演算法分析: 1、通過ReverseString(s,0,5)交換字串第0位和第5位的字元,將I am a stud

倒轉一個句子,如果輸入的句子為I am a student. 輸出為:student. a am I

法一: #include<stdio.h>#include<string.h>void main(){ int i,k=0,j=0;char ss[100],s[10][20];gets(ss);for(i=0;ss[i];i++)if(ss[i]!=

用程式碼實現輸入i am a student ,輸出 student a am i,不能用類庫函式

1.輸入i am a student ,輸出student a am i,不能用類庫函式 public static void main(String[]args){ String s1 = "i am a student"; //獲取到擷取後的字串陣列 String[

輸入一個英文句子,翻轉句子中單詞的順序,但單詞內字元的順序不變。(筆試題) 句子中單詞以空格符隔開。為簡單起見,沒有標點符號。 例如輸入“I am a student”,則輸出“student a

輸入一個英文句子,翻轉句子中單詞的順序,但單詞內字元的順序不變。(筆試題)句子中單詞以空格符隔開。為簡單起見,沒有標點符號。例如輸入“I am a student”,則輸出“student a am I” #include <stdio.h> #include

面試經典題目:字串翻轉I am a student

只有比別人更早、更勤奮地努力,才能嚐到成功的滋味 題目:寫一個函式,將字串翻轉,翻轉方式如下:“I am a student”反轉成“student a am I”,不借助任何庫函式 ,要求單詞

C語言: 有一個字元陣列的內容為:"student a am i", 請你將陣列的內容改為"i am a student".

題目:有一個字元陣列的內容為:"student a am i", 請你將陣列的內容改為"i am a student".     要求:不能使用庫函式。只能開闢有限個空間(空間個數和字串的長度無關)。 分析:分為兩大部分:①把整個字元陣列逆置                

C 語言字串 將一行字串I am a student。逆序輸出student。a am I;

方法1 #include <stdio.h> #include <string.h> #define N 4//單詞的個數 #define M 20//單詞的長度 int main(void) {char str[N][M],str1[M];int