problem 小红大战小紫
describe
小红正在和小紫对战,给定两个人的胜场数量,请你判断最终是谁获胜了。
solution
判断数字的大小
code
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a,b;
int main()
{
cin >> a>>b;
if(a>b) cout << "kou"<<endl;
else if(a==b) cout << "draw"<<endl;
else cout << "yukari"<<endl;
}
problem 小红的白日梦
describe
小红经常会做梦,但她比较喜欢做白日梦。
已知小红白天做梦可以获得 2 点幸福度,晚上做梦可以获得 1 点幸福度。现在给定小红每天中午和晚上睡觉的做梦情况。她可以每天将晚上的梦提前移到白天来做,请问小红总共最多可以获得多少幸福度?
注:只有当白天没做梦且晚上做梦的时候才可以移动梦境。
solution
一个Y为2,两个Y为3,没有Y为0
code
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a,b;
int main()
{
cin >> a;
string s1,s2; //中午 晚上
cin >> s1>>s2;
b=0;
int re=0;
for(int i=0;i<a;i++)
{
re=0;
if(s1[i]=='Y') re++;
if(s2[i]=='Y') re++;
if(re==1) b+=2;
else if(re==2) b+=3;
else if(re==0) b+=0;
}
cout << b<<endl;
}
problem 小红的小小红
describe
小红拿到了一个字符串,其中一定包含连续子串"xiao",和连续子串"hong"。
请你将字符串重排,使得该字符串包含"xiaohong"的连续子串。
solution
先输出“xiaohong”,之后输出剩余的字符
code
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
using ll = long long;
#define endl '\n'
int main()
{
string s;
cin >> s;
int x[26] = {0};
for (auto i : s)
{
x[i - 'a']++;
}
string s1 = "xiaohong";
for (auto i : s1)
{
x[i - 'a']--;
}
cout << "xiaohong";
for (int i = 0; i < 26 ; i++)
{
for (int j = 0; j < x[i]; j++)
{
cout << char(i + 'a');
}
}
}
problem 小红的中位数
describe
小红拿到了一个数组:a1,a 2,…,an。她定义 f(i) 为,删除第i个元素后,数组的中位数。现在小红想让你求出f(1),f(2)…f(n)的值,你能帮帮她吗?
solution
先排序,之后根据数组的长度来输出中位数。
code
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n), ans(n);
for (int& ai : a) { cin >> ai; }
vector<pair<int, int>> p;
for (int i = 0; i < n; i += 1) { p.emplace_back(a[i], i); }
sort(p.begin(), p.end());
for (int i = 0; i < n; i += 1) {
if (n % 2) {
int j = n / 2 - 1, k = n / 2;
if (j >= i) { j += 1; }
if (k >= i) { k += 1; }
ans[p[i].second] = p[j].first + p[k].first;
} else {
int j = n / 2 - 1;
if (j >= i) { j += 1; }
ans[p[i].second] = p[j].first * 2;
}
}
for (int x : ans) { cout << x / 2 << "." << (x % 2 * 5) << "\n"; }
}
problem 小红构造数组
describe
小红希望你构造一个数组,满足以下三个条件:
- 数组的元素都是素数。
- 数组所有元素相乘恰好等于x。
- 数组任意相邻两个元素不等。
code
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define ls u << 1
#define rs u << 1 | 1
#define all(x) x.begin(),x.end()
#define int long long
#define i128 __int128
inline int gcd(int a, int b) {return b > 0 ? gcd(b, a % b) : a;}
inline int lowbit(int x) {return x & (-x);}
int qmi(int a, int b, int mod){int res = 1;while(b) {if(b & 1) res = res * a % mod;a = a * a % mod;b >>= 1;}return res;}
inline i128 read(){i128 x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;}
inline void print(i128 x){if(x < 0){putchar('-');x = -x;}if(x > 9)print(x / 10);putchar(x % 10 + '0');}
void solve()
{
int x; cin >> x;
vector<PII>a;
int sum = 0;
if(x == 1) {
cout << -1 << '\n';
return;
}
for(int i = 2; i * i <= x; i ++) {
if(x % i == 0) {
int cnt = 0;
while(x % i == 0) {
cnt ++; x /= i;
}
a.push_back({cnt, i});
sum += cnt;
}
}
if(x > 1) a.push_back({1, x}), sum += 1;
sort(all(a), greater<PII>());
vector<int>v(sum);
int j = 0;
for(int i = 0; i < sum; i += 2) {
v[i] = a[j].y;
a[j].x --;
if(a[j].x == 0) j ++;
}
for(int i = 1; i < sum; i += 2) {
v[i] = a[j].y;
a[j].x --;
if(a[j].x == 0) j ++;
}
for(int i = 0; i < sum - 1; i ++)
if(v[i] == v[i + 1]) {
cout << -1 << '\n';
return;
}
cout << sum << '\n';
for(int i = 0; i < sum; i ++) cout << v[i] << ' ';
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
}