2019年1月“最强代码”冬季赛

这是一个签到题

 

Description

 

众所周知,中国矿业大学将在2019年6月1日迎来建校110周年。但是Alice想知道在哪一年中国矿业大学会迎来n周年纪念。

Input

 

一行,一个整数n(1<=n<=200),代表中国矿业大学n周年。

Output

 

在一行中输出一个正整数x,表示在x年,中国矿业大学会迎来n周年纪念。

Sample Input 1 

110

Sample Output 1

2019

AC code:

#include<iostream>

using namespace std;

int main() {
	int n;
    cin >> n;

    cout << n + 1909 << endl;
    
	return 0; 
}

  

壮壮与月亮女神

 

Description

 

能与壮壮哥平分秋色的放眼学校仅有月亮女神一人。这天你奉壮壮哥之名劝说月亮女神归顺壮壮哥。但是作为全校第二能打的,岂是那么轻易就能见面的?月亮女神宿舍门上有一个n阶方阵,如果你能按照s型依次将1~n^2填入方阵,你就能见到月亮女神。

Input

 

一行,一个整数n代表矩阵的阶数(0 < n < 500)

Output

 

n行,每行n个整数,用空格分隔,代表第i行矩阵元素。

Sample Input 1 

3

Sample Output 1

1 2 3
6 5 4
7 8 9

AC code:

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;

    vector<vector<int>> temp(n, vector<int>(n, 0));

    int flag = 1;
    int curNum = 1;

    for (int i = 0; i < n; ++i) {
        if (flag == 1) {
            for (int j = 0; j < n; ++j) {
                temp[i][j] = curNum++;
            }
            flag = 0;
        } else {
            for (int j = n-1; j >= 0; --j) {
                temp[i][j] = curNum++;
            }
            flag = 1;
        }
    }

    for (int i = 0; i < n; ++i) {
        cout << temp[i][0];
        for (int j = 1; j < n; ++j) {
            cout << " " << temp[i][j];
        }
        cout << endl;
    }

    return 0;
}

  

月亮女神的魔法

 

Description

 

月亮女神是田径好手,有一天她在参加扔铁饼比赛时,惨遭壮壮哥的羞辱,0:5惨败!于是次日她想用魔法来找回面子。月亮女神会如下两个魔法:1.月亮女神的加速:使铁饼飞a米。2.月亮女神全身变:使a变为a+5。现给出初始的a与月亮女神可以使用魔法的次数t,求她最远能将铁饼扔多远。

Input

 

一行,两个整数,a和t,其含义如题意所述。(0<=a,t<=1000)

Output

 

一行,一个整数,即铁饼最远能飞多少米。

Sample Input 1 

20 20

Sample Output 1

720

my code:

#include <iostream>
#include <vector>

using namespace std;

int dfs(int m, int n, int temp);

vector<vector<int>> memo(10000, vector<int>(1005, 0));

int main() {
    int m, n;

    cin >> m >> n;

    cout << dfs(m, n, 0) << endl;

    return 0;
}

int dfs(int m, int n, int temp) {
    if (n <= 0) return temp;
    if (memo[m][n] != 0) return memo[m][n];
    memo[m][n] = temp;
    return max(dfs(m, n-1, temp+m), dfs(m+5, n-1, temp));
}

  

Analysis:

刚开始想到的就是用dfs来深搜,但是当数据达到100是就已经计算不出来结果了(TLE),于是我又加了一个memo用来存储已经处理过的状态,虽然速度提高了很多,但是最后提交的时候还是没能通过。

壮壮的心理学

 

Description

 

别看壮壮又高又壮,但她其实是个心思细腻的女孩,也是个心理学高手!每天壮壮哥都要检阅她的小弟,而小弟总会拍一句马屁,壮壮想知道谁说的是真的,谁说的是假的。已知共n个人,依次从1~n编号,每个人说一句话,如果该话长度为奇数,即为假话,偶数为真话。

Input

 

第一行一个整数n(0<n<100000),为小弟个数。接下来n行,每行一个字符串,为小弟说的话。

Output

 

一个整数a,a为说真话的人的总数。

Sample Input 1 

3
Zhuangzhuanggehaoshuai
Aaaa
lihai

AC code:

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        string str;
        cin >> str;
        if (str.length() % 2 == 0)
            ans++;
    }

    cout << ans << endl;

    return 0;
}

  

统计某类完全平方数

 

Description

 

统计给定区间(100~n)内的三位数中有两位数字相同的完全平方数(如144、676)的个数。

Input

 

一个整数n,(1000>n>=100)

Output

 

一个整数n。

Sample Input 1 

500

Sample Output 1

6
My code:
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;

    int ans = 0;
    for (int i = 11; i < 32 && i*i <= n; ++i) {
        int cur = i * i;
        int g = cur % 10;
        int s = (cur / 10) % 10;
        int b = (cur / 100) % 10;
      	cout << b << s << g << endl;
        if (g == s || g == b || s == b) ans++;
    }

    cout << ans << endl; 

    return 0;
}

  

 Analysis:
感觉是很简单的一道题,但是不知道为什么提交的时候总是出错。
 
 

会魔法的Alice

 

Description

 

Alice和Bob在一起玩一个游戏,游戏通关的条件是使这个数列的和为0,但有时候数列的和并不是0,但是Alice会魔法,她可以把一个数变成自己的相反数,并且Alice只有一次使用魔法的机会。请问你Alice和Bob能不能通关呢?当然,如果数列刚开始的和就是0,也可以通关。

Input

 

第一行包含一个正整数n(1<=n<=1e5),表示数列的个数第二行有n个数Xi(1<=i<=n, -100<=x<=100),表示这个数列。

Output

 

如果Alice和Bob可以通关,输出“YES”,否则输出“NO”。(输出不包括双引号)

Sample Input 1 

5
1 3 -5 3 4

Sample Output 1

YES

Hint

可以把其中一个3变为-3,最后数列和为0。符合通关条件。

AC code:

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> temp;

    int sum = 0;
    for (int i = 0; i < n; ++i) {
        int num;
        cin >> num;
        temp.push_back(num);
        sum += num;
    }

    if (sum == 0) {
        cout << "YES" << endl;
        return 0;
    }

    for (int i = 0; i < n; ++i) {
        if (temp[i] == sum/2) {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
    return 0;
}

  

2^k的和

 

Description

 

如果一个正整数n满足其值为2^k(其中k为正整数),例如32,16。我们称这种数为2^k整数。但这种数毕竟很少,现在定义2^k半整数,虽然n不满足2^k整数,但n可以由两个2^k整数相加得到,这样的n我们称为2^k半整数(其中k为正整数)。当然2^k整数也满足2^k半整数。例如32可以由16和16相加而成,48可以由32和16相加而成。

Input

 

第一行一个整数t(1<=t<=20),表示t组数据。接下来有t行,每行一个整数n。(1<=n<=1e6)

Output

 

如果n是2^k半整数,输出Yes,否则输出No。

Sample Input 1 

3
48
49
32

Sample Output 1

Yes
No
Yes

My code:

#include <iostream>
#include <vector>
#include <set>

using namespace std;

vector<int> temp;
set<int> memo;

void init(int x) {
    for (int i = 0; i < x; ++i) {
      	temp.push_back(2<<i);
      	memo.insert(2<<i);
    }
        
    for (int i = 0; i < temp.size(); ++i) {
        for (int j = 0; j < temp.size(); ++j) {
            memo.insert(temp[i]+temp[j]);
        }
    }
}

int main() {
    int n;
    cin >> n;

    init(20);

    for (int i = 0; i < n; ++i) {
        int num;
        cin >> num;
        if (memo.count(num)) 
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

  

Analysis:

我把所有的可能都遍历出来,然后存储在set中,然后在查询,不知道为什么最后还是会出错。可能是不应该把两个相同的数相加吧。

战士、魔法师、射手

 

Description

 

这一天Bob接触了角色扮演游戏,其中包含战士(warrior)、魔法师(enchanter)、射手(shooter)三个职业,Bob创建了n个账号,每个账号的编号是1~n,且没有任何两个账号的编号相同。每个账号的职业可能是战士、魔法师、射手中的一种。这时候Bob定义了一种排序,职业排序。规则是这样的:首先规定三个职业的先后顺序,职业1,职业2,职业3,意味着这样的顺序:职业1的所有单位在职业2的所有单位和职业3的所有单位的前面,职业2的所有单位在职业3的所有单位之前。但是要注意:职业间的相对顺序不发生改变。假如给出的排序规则是,warrior,enchanter,shooter,那么所有的warrior排在最前面,紧接着是enchanter,最后shooter。如果其中没有一个相对的职业,则跳过该种族

Input

 

第一行包含一个正整数n(1<=n<=100),代表Bob创建了n个账号。接下来n行,每行的输入一个字符串,格式为:“ID is 职业”,中间以一个空格隔开。其中ID为1~n的正整数,且每个ID唯一。职业是一个字符串,保证是warrior,enchanter,shooter 三种职业中的一种。最后一行包含三个字符串:职业1 职业2 职业3。中间用一个空格隔开,代表职业排序的先后顺序。

Output

 

对于每组数据,按照 职业1 职业2 职业3的排序规则,在一行输出排序后的ID序列,两个ID之间用一个空格隔开。

Sample Input 1 

5
1 is warrior
2 is enchanter
3 is shooter
4 is warrior
5 is warrior
warrior enchanter shooter

Sample Output 1

1 4 5 2 3

Sample Input 2 

4
1 is warrior
4 is warrior
3 is warrior
2 is shooter
shooter enchanter warrior

My code:

#include <iostream>
#include <map>
#include <vector>
#include <string>

using namespace std;

map<string, vector<int>> m;

int main() {
    int n;
    cin >> n;
    getchar();

    for (int i = 0; i < n; ++i) {
        string str;
        getline(cin, str);

        int pos1 = str.find(' ');
        string num = str.substr(0, pos1);

        int pos2 = str.find(' ', pos1+1);
        string name = str.substr(pos2+1);

        m[name].push_back(stoi(num));
    }

    vector<int> ans;

    string str;
    getline(cin, str);

    int pos1 = str.find(' ');
    string name1 = str.substr(0, pos1);
    if (m.count(name1))
        for (int i = 0; i < m[name1].size(); ++i) 
            ans.push_back(m[name1][i]);
            
    int pos2 = str.find(' ', pos1+1);
    string name2 = str.substr(pos1+1, pos2-pos1-1);
    if (m.count(name2))
        for (int i = 0; i < m[name2].size(); ++i) 
            ans.push_back(m[name2][i]);

    string name3 = str.substr(pos2+1);
    if (m.count(name3))
        for (int i = 0; i < m[name3].size(); ++i) 
            ans.push_back(m[name3][i]);
    
	if (!ans.empty()) {
        cout << ans[0];
        for (int i = 1; i < ans.size(); ++i) {
            cout << ' ' << ans[i];
        }
        cout << endl;
    }

    return 0;
}

  

Analysis:

用STL中的string操作了一波,样例过了,但是最后还是没有AC。

两小儿又来取石子

 

Description

 

Alice和Bob这天又约出来一起玩游戏,但这次取石子的方式稍有不同。有n个石子摆成一排,编号为1~n,Alice和Bob每次可以取1~k个连续编号的石子,假设他们都很聪明,都选取最优的选法,Alice先手,如果谁不能取石子了,则为输。

注意:石子按照一排排列,例如n=3,k=2, 3个石子编号为1 2 3,每次可以取1~2个石子,Alice先把2号石子取走,这时候Bob不能拿走1 3,因为1和3号石子的编号不连续,Bob只能拿走1号或者2号石子,最后Alice拿走最后一个。Bob输。

Input

 

两个整数n和k。其中 0<=n<=100, 1<=k<=100。

Output

 

若Alice不能取石子,输出“Bob”,否则输出“Alice”。

Sample Input 1 

3 2

Sample Output 1

Alice

Sample Input 2 

2 1

Sample Output 2

Bob

Code:

waiting...........

校霸争夺会

 

Description

 

新生入校,壮壮双手抱胸,目光凌厉的审视着每一个新生,寻找可能的对手。校霸的评定分为琴棋书画四个方面,虽然壮壮一样不通,但是她能打,凡是报名校霸选举的,都会被壮壮打到休学。不懂规矩的你一入学就报了名,现在你的内心忐忑不安,决定向壮壮哥示好。向壮壮示好最佳方式就是记住她的生日,壮壮哥会告诉你今天的日期以及她出生多少天了,请你算出她的生日。注意,如果不能在一秒钟答出,你会挨揍。

Input

 

第一行是今天的日期,按yyyy mm dd形式给出。保证输入日期合法。第二行一个整数t,表示壮壮出生了t天。(题目保证日期符合规范,0 <= t <= 100000,其中日期规则按照万年历,即国际通用日历计算)

Output

 

一行,yyyy-mm-dd形式,代表壮壮出生日期。

Sample Input 1 

2019 01 10
10

Sample Output 1

2019-01-01

Code:

wait...........

猜你喜欢

转载自www.cnblogs.com/ruruozhenhao/p/10251900.html