喵哈哈村的魔法考试 Round #3 (Div.2) 题解

时间:2023-03-09 17:16:31
喵哈哈村的魔法考试 Round #3 (Div.2) 题解

A

题解:保证一个三角形的话,得两边之和大于第三边才行,所以都拿来判一判就好了。

#include <iostream>
using namespace std;
int main(){
int t,a,b,c;
cin>>t;
while(t--){
cin>>a>>b>>c;
if(a+b<=c){
cout<<"No"<<endl;
continue;
}
else if(a+c<=b){
cout<<"No"<<endl;
continue;
}
else if(b+c<=a){
cout<<"No"<<endl;
continue;
}
else{
cout<<"Yes"<<endl;
continue;
}
}
return 0;
}

B

题解:令len为字符串的长度,那么T/len个循环,再暴力枚举T%len长度的答案就好了。

include

#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <numeric>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <tuple>
#include <cassert> #define for_each_test_cases(T) int T; scanf("%d", &T); for (int cas = 1; cas <= T; cas++) const int MaxN = 5005;
char s[MaxN];
int n, m; std::pair<int, int> move(const std::pair<int, int>& now, const char& c) {
if (c == 'E') return std::make_pair(now.first + 1, now.second);
if (c == 'S') return std::make_pair(now.first, now.second - 1);
if (c == 'W') return std::make_pair(now.first - 1, now.second);
/* N */ return std::make_pair(now.first, now.second + 1);
} int main() {
scanf("%s%d", s, &m);
n = strlen(s);
std::pair<int, int> now(0, 0), dir(0, 0);
for (int i = 0; i < n; i++) {
dir = move(dir, s[i]);
}
now = std::make_pair(dir.first * (m / n), dir.second * (m / n));
m %= n;
for (int i = 0; i < m; i++) {
now = move(now, s[i]);
}
printf("%d %d\n", now.first, now.second);
return 0;
}

C

题解:正常想法是随机,感觉上来说随机几次就能AC。但是随机种子,决定了你的随机数。Srand(time(NULL))是不行的,因为这个OJ采用的是并发测评的模式,所以你获取的TIME(null)种子是一样的。

这儿一个正确做法是,抓取定义字符的内存,这个内存地址是随机的,然后来随机就好了。

个人觉得 做法千千万,只要能AC就行。

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h> int main() {
int* a = new int[5];
srand((unsigned long) a);
delete[] a;
printf("%d\n", (rand() & 1) + 1);
return 0;
}

D

题解:实际上n=100嘛,就直接暴力n^3for一下就好了嘛。如果不知道怎么算面积的话,去百度搜海伦公式。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <numeric>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <tuple>
#include <cassert> #define for_each_test_cases(T) int T; scanf("%d", &T); for (int cas = 1; cas <= T; cas++) const int MaxN = 105;
int n;
int a[MaxN]; int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
std::sort(a, a + n);
double res = -1;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = j + 1; k < n; k++) {
if (a[i] + a[j] <= a[k]) continue;
double p = (a[i] + a[j] + a[k]) / 2.0;
res = std::max(res, sqrt(p * (p - a[i]) * (p - a[j]) * (p - a[k])));
}
}
}
printf("%.0f\n", res);
return 0;
}

E

题解:

直接数日历嘛(不

你以某一天为基准,然后暴力推2016年的所有天,是星期几就好了。

#include<iostream>
using namespace std;
int main()
{
int k;
string j;
char s[6];
while(cin>>k>>j>>s)
{
if(s[0]=='w')
{
if(k==5||k==6)
{
cout<<"53"<<endl;
}
else cout<<"52"<<endl;
}
else
{
if(k==30)
{
cout<<"11"<<endl;
}
if(k==31)
{
cout<<"7"<<endl;
}
if(k!=30&&k!=31)
{
cout<<"12"<<endl;
}
}
}
return 0;
}