牛客小白月賽7
github博客地址
比賽鏈接
A. 送分題
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin >> n;
if(n < 20180001)
cout << n + 2017 << endl;
else
cout << 20182017 << endl;
return 0;
}
C. 誰(shuí)是神射手
思路: 列出前幾次概率: 1. a: ,b:
; 2. a :
, b:
比較 兩邊概率大小時(shí),不管是第幾層蝴蜓,都會(huì)約成
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
if (100 * a > (100 - a) * b)
cout << "MWH" << endl;
else if (100 * a < (100 - a) * b)
cout << "CSL" << endl;
else
cout << "equal" << endl;
return 0;
}
E. Applese的超能力
硬幣個(gè)數(shù) n 仅颇, m 個(gè)硬幣合并一次
n == 1
单默,直接yes
如果
n != 1
且m == 1
永遠(yuǎn)合并不完普通情況,先從
n
個(gè)中取出1
枚忘瓦,從n - 1
個(gè)中取出m - 1
枚搁廓,總共取了m
枚。 然后把合成好的一枚硬幣還回去耕皮,剩下n - m + 1
枚境蜕,重復(fù)上面的操作,先去1
枚凌停,再取m - 1
枚 …… 粱年,可以發(fā)現(xiàn),如果n - 1
枚里 正好有整數(shù)個(gè)m - 1
,就可以一直和獨(dú)立的那一枚合并罚拟,直到1
枚台诗。
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ll n, m;
cin >> n >> m;
if (n == 1)
cout << "Yes" << endl;
else if (m == 1)
cout << "No" << endl;
else if ((n - 1) % (m - 1) == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
F. BFS
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
for (auto& i : s)
i = toupper(i);
int item;
if ((item = s.find("BOB")) != s.npos)
cout << item << endl;
else
cout << -1 << endl;
return 0;
}
G. CSL分蘋果
無(wú)腦背包完箩。 先算出總質(zhì)量,然后除以 2
拉队,這就是第一個(gè)人的背包上限弊知,然后求最優(yōu)解, 總質(zhì)量減去這個(gè)數(shù)粱快,就是另一人的
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
int a[102] = {0}, sum = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
sum += a[i];
}
int tmp = sum;
sum /= 2;
int ans[10002] = {0};
for (int i = 0; i < n; i++)
for (int j = sum; j >= a[i]; j--)
ans[j] = max(ans[j], ans[j - a[i]] + a[i]);
cout << ans[sum] << ' ' << tmp - ans[sum] << endl;
return 0;
}
I. 新建 Microsoft Office Word 文檔
編號(hào)放
set
里新建時(shí)秩彤,取
set 首
并從set
中刪除編號(hào)刪除時(shí),向
set
中 插入編號(hào)皆尔,若set.size()
增大了呐舔,說(shuō)明之前沒(méi)有這個(gè)號(hào),刪除成功慷蠕。反之珊拼,失敗
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, id;
string s;
cin >> n;
set<int> st;
for (int i = 1; i <= n; i++)
st.insert(i);
while (n--)
{
cin >> s;
if (s == "New")
{
cout << *st.begin() << endl;
st.erase(st.begin());
}
else
{
cin >> id;
int size = st.size();
st.insert(id);
if (st.size() == size)
cout << "Failed" << endl;
else
cout << "Successful" << endl;
}
}
return 0;
}