牛客小白月赛56
signed main() {
int a = read(), b = read(), n = read();
LL mi = 1 * n;
LL ma = a * n + b * n;
cout << mi << ' ' << ma << endl;
return 0;
}
int main() {
int m = read();
if(m < 2) cout << 1 << endl;
else {
cout << 2 << endl;
}
for(int i = 0; i < m; i++) cout << 1 << ' ';
cout << endl;
return 0;
}
思路:
从小到大按1-9、11-19...这样排。
代码:
int main() {
int n = read();
for(int i = 1; i <= n; i++) w[i] = read();
sort(w + 1, w + 1 + n);
int cnt = n / 10;
int k = 1;
for(int i = 1; i <= cnt; i++) ans[i*10] = w[k++];
if(n % 10 == 0) {
for(int i = 1; i <= 9; i++) {
for(int j = 0; j < cnt; j++) {
ans[i + j * 10] = w[k++];
}
}
}else {
for(int i = 1; i <= 9; i++) {
for(int j = 0; j <= cnt; j++) {
if(i + j * 10 > n) continue;
ans[i + j * 10] = w[k++];
}
}
}
for(int i = 1; i <= n; i++) cout << ans[i] << ' ';
cout << endl;
return 0;
}
思路:
先预处理,把估计范围的质数全部筛出来,然后再预处理1-i的最小未出现质数,这里我当时用的是二分,但是过不了后面的数据。直接暴力++就行了。
代码:
/*
qwq!
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <unordered_map>
using namespace std;
#define pb push_back
#define pu push
#define fi first
#define se second
#define LL long long
typedef pair<int,int> PII;
const int INF = 0x3f3f3f3f;
const int N = 5e6 + 10;
int w[N];
int primes[N], cnt;
int ans[N];
bool st[N];
map<int,bool>stx;
void get_primes() {
for(int i = 2; i <= N; i++) {
if(!st[i]) primes[cnt++] = i;
for(int j = 0; primes[j] <= N / i; j++) {
st[primes[j] * i] = true;
if(i % primes[j] == 0) break;
}
}
}
int read () {
int k=0,f=1;
char c=getchar ();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar ();}
while (c>='0'&&c<='9') {k=k*10+c-'0';c=getchar ();}
return k*f;
}
bool check(int x) {
if(x < 2) return false;
for(int i = 2; i <= x / i; i++)
if(x % i == 0) return false;
return true;
}
int main() {
int n = read(), q = read();
for(int i = 1; i <= n; i++) w[i] = read();
get_primes();
int now = 0;
ans[0] = primes[now];
for(int i = 1; i <= n; i++) {
if(w[i] == primes[now]) {
now++;
while(stx[primes[now]]) now++;
ans[i] = primes[now];
}else ans[i] = primes[now];
stx[w[i]] = 1;
}
while(q--) {
int x = read();
cout << ans[x] << endl;
}
return 0;
}
思路:尽量让两个Z靠拢。
代码:
int main() {
int n = read(), k = read();
string s; cin >> s;
s = 'x' + s;
int cnt = 0, last = -1;
for(int i = 1; i <= n; i++) {
if(s[i] == 'Z' && last == -1) {
last = i;
}else if(s[i] == 'Z'){
w[cnt++] = i - last - 1;
last = i;
}
}
sort(w, w + cnt);
int ans = 0;
// for(int i = 0; i < cnt; i++) cout << w[i] << ' ';
// cout << endl;
for(int i = 0; i < cnt; i++) {
if(k < w[i]) break;
ans += 4;
k -= w[i];
}
cout << ans << endl;
return 0;
}