灰原哀 - 高清图片,堆糖,美图壁纸兴趣社区

牛客周赛 Round 29

A-小红大战小紫

模拟

1
2
3
4
5
6
7
8
9
10
11
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
if(a == b) cout << "draw\n";
else if(a > b) cout << "kou\n";
else cout << "yukari\n";
return 0;
}

B-小红的白日梦

尽量换到白天即可

都等于没办法

一个等于就加2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <bits/stdc++.h>
using namespace std;
string s[2];
int main()
{
int n, sum = 0;
cin >> n >> s[0] >> s[1];
for(int i = 0; i < n; i ++)
{
if(s[0][i] == 'Y' && s[1][i] == 'Y') sum += 3;
else if(s[0][i] == 'Y' || s[1][i] == 'Y') sum += 2;
}
cout << sum << endl;

return 0;
}

小红的小红红

分别找到"xiao""hong",然后进行删除即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
cin >> s;
//找到“xiao”
int i = s.find("xiao");
//删除
s.erase(i, 4);
//找到“hong”
i = s.find("hong");
//删除
s.erase(i, 4);
//直接输出
cout << "xiaohong" << s << endl;

return 0;
}

小红的中位数

暴力肯定不可以,应该是规律题

观察一下每次删除一个数字中位数的变化情况

来自题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
struct Index{
int id;
//ai的下标,使数组b能够以ai原先的顺序记录ai时的中位数,同时使数值不爆数组上限;
int num;
//ai的数值.
}a[N];
int b[N];
//记录ai时的中位数。
bool cmp(Index a,Index b){
return a.num<b.num;
//将数值从小到大排
}

void f(int x){
double w=1.0*x/2;
//计算中位数的值,x*0.1是将数值类型由实数转化为浮点型;
printf("%.1f\n",w);
//输出保留一位小数的值;
}
int main() {
int n;
cin >>n;
//数组长度
for (int i=0;i<n;i++)
{
cin >>a[i].num;
//记录ai的数值;
a[i].id=i;
//记录ai的下标;
}
sort(a,a+n,cmp);
//对原数组进行排序;
if (n%2==1)
//当n为奇数时,所求数组为n-1,即实际数组长度为偶数;
{
for (int i=0;i<n/2;i++)
b[a[i].id]=a[n/2].num+a[n/2+1].num;
b[a[n/2].id]=a[n/2-1].num+a[n/2+1].num;
for (int i=n/2+1;i<n;i++)
b[a[i].id]=a[n/2-1].num+a[n/2].num;
}
else
//当n为偶数时,实际长度为奇数;
{
for (int i=0;i<n/2;i++)
b[a[i].id]=a[n/2].num*2;
for (int i=n/2;i<n;i++)
b[a[i].id]=a[n/2-1].num*2;

}
for (int i=0;i<n;i++)f(b[i]);

return 0;
}

小红构造数组

质因数分解·,然后按奇数,偶数进行放置即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 1e6 + 10;
// len用来储存输出的长度, outLine用来储存需输出的数组
ll len, outLine[N];
//
typedef struct Map{
ll key, value;
}Map;

Map mp[N];

bool cmp(Map a, Map b){return a.value > b.value;}

int main()
{
ll x, ans = 0, cnt = 0;
cin >> x;
if(x == 1) return cout << "-1\n", 0;
while(x % 2 == 0)//先排除2,利于减少下面的for()循环次数
{
if(!cnt) cnt ++;
ans ++, x /= 2, mp[cnt].key = 2, mp[cnt].value ++;
}
len += ans;
for(ll i = 3; i * i <= x; i += 2)
{
ans = 0;
if(x % i == 0) {
ans = 0, cnt ++;
mp[cnt].key = i;
while (x % i == 0)
x /= i, ans++, mp[cnt].value ++;
}
len += ans;
}
if(x > 1)//判断是否除尽,未除尽的需存储到数组中
{
len ++, cnt ++;
mp[cnt].key = x, mp[cnt].value = 1;
}
sort(mp + 1, mp + 1 + cnt, cmp);//根据数量从大到小排序
if(mp[1].value > (len + 1) / 2)
cout << "-1\n";
else
{
cout << len << endl;
int temp = 1;
for(int i = 0; i < len; i += 2)//储存于奇数位中
{
if(!mp[temp].value) temp ++;
outLine[i] = mp[temp].key;
mp[temp].value --;
}
for(int i = 1; i < len; i += 2)//储存于偶数位中
{
if(!mp[temp].value) temp ++;
outLine[i] = mp[temp].key;
mp[temp].value --;
}
for(int i = 0; i < len; i ++) cout << outLine[i] << " \n"[i == len - 1];
}

return 0;
}