今天下午總算把好久之前沒打的div3開了一場vp,補掉了,全暴力,除了自己讀題傻逼以外沒什麼好說的,,
A |
standard input/output 1 s, 256 MB |
x3717 | |
B |
standard input/output 2 s, 256 MB |
x4380 | |
C |
standard input/output 1 s, 256 MB |
x2792 | |
D |
standard input/output 2 s, 256 MB |
x1395 | |
E |
Two Arrays and Sum of Functions standard input/output 2 s, 256 MB |
x794 | |
F1 |
Microtransactions (easy version) standard input/output 2 s, 256 MB |
x179 | |
F2 |
Microtransactions (hard version) standard input/output 3 s, 256 MB |
x176 |
A:給出n,x,y,以及n長度的str(01串),可以01相互改變,問你最少多少次操作使得 str % 10^y = 10^x 瞎搞記錄一下就可以
int main()
{
int x,y;
while(cin >> n >> x >> y){
string str;
cin >> str;
int ans = 0,cnt = 0;
for(int i = str.size() - 1;i >= 0;i--){
if(cnt == y){
if(str[i] == '0') str[i] = '1',ans++;
break;
}
if(str[i] == '1') ans++,str[i] = '0';
cnt++;
}
cnt = 0;
for(int i = str.size() - 1;i >= 0;i--){
if(cnt == y) ;
else{
if(cnt == x) break;
else if(str[i] == '1') ans++;
}
cnt++;
}
wt(ans);
}
return 0;
}
B:第i天可以解決i個問題,如果第i天剩下的問題都沒有大於i的,就停止訓練了,貪心排序判斷一下
for(int i = 1;i <= n;i++) cin >> a[i];
sort(a + 1,a + 1 + n);
ll ans = 0;
for(int i = 1;i <= n;i++){
ans++;
if(ans > a[i]){
while(i + 1 <= n && ans > a[i + 1]){
i++;
}
i++;
if(ans > a[i]){
ans--;break;
}
}
}
cout << ans << endl;
}
return 0;
C:判斷好的字符串,給了good的定義,直接算
D:給了一些數的所有的因子,除了1和本身,問你存不存在這個數,並且輸出最小的
拿最小的和最大的乘積去check這些因子的個數就可以,因爲所有的都在裏面,那a[1]*a[n]肯定就是這個乘積了。注意判斷所有數是否整除他們,並且因子個數相同
int main()
{
int t;
ios::sync_with_stdio(false);
cin >> t;
while(t--){
cin >> n;
for(int i = 1;i <= n;i++) cin >> a[i];
sort(a + 1,a + 1 + n);
ll num = a[1] * a[n];
set<int>s;
for(ll i = 2;i * i <= num;i++){
if(num % i == 0) s.insert(i),s.insert(num / i);
}
// cout << s.size() << endl;
if(s.size() != n){
wt(-1);
continue;
}else{
for(int i = 1; i<= n;i++){
if(num % a[i] != 0){
wt(-1);
goto kkk;
}
}
}
wt(num);
kkk:;
}
return 0;
}
E:求題上的那個公式,水題+1,
1 * 5 5
2 * (4 + 4) 8
3 * (3 + 3 + 3) 9
4 * (2 + 2 + 2 + 2) 8
5 * (1 + 1 + 1 + 1 + 1) 5
1 1
1 2
1 3
1 4
1 5
2 2
2 3
2 4
2 5
3 3
3 4
3 5
4 4
4 5
5 5
你會發現,每個數的貢獻很容易可以得到,就是(n - i + 1) * i * a[i],上面的數是不變的,那麼可以先乘上,然後一起排序就完了,算貢獻就可以了,注意取模,細節
int main()
{
while(cin >> n){
for(int i = 1;i <= n;i++) cin >> a[i];
for(int i = 1;i <= n;i++) cin >> b[i];
for(ll i = 1;i <= n;i++){
a[i] *= ((n - i + 1) * i);
}
sort(a + 1,a + 1 + n);
sort(b + 1,b + 1 + n,greater<int>());ll ans = 0;
for(int i = 1;i <= n;i++){
// cout << a[i] << " " << b[i] << endl;
ans += (a[i] % 998244353ll) * (b[i] % 998244353);
ans %= 998244353ll;
}
wt(ans);
}
return 0;
}
F1,F2 n個東西,對於每個東西,你都需要a[i]個,原價2金幣,每天你可以獲得1金幣,並且他有m個優惠,優惠的那天是1金幣,問你最少多少天就可以買完所有的東西
會了F1的寫法,很快就二分改出F2的了
int vis[200024];
int id[200024],m;
P p[maxn];
bool check(ll x){
MS1(vis);
for(int i = 1;i <= m;i++){
if(p[i].fi <= x) vis[p[i].se] = max(vis[p[i].se],p[i].fi);
}
// for(int i = 1;i <= x;i++){
// cout << vis[i] << " " ;
// }
// cout << endl;
vector<vector<int> > off(200011);
for(int i = 1;i <= n;i++){
if(vis[i] != -1) off[vis[i]].pb(i);
}
for(int i = 1;i <= n;i++) b[i] = a[i];
int num = 0;
for(int i = 1;i <= x;i++){
num++;
if(i > 200000){
num += (x - i);break;
}
for(auto d:off[i]){
if(num >= b[d]){
num -= b[d];b[d] = 0;
}else{
b[d] -= num;
num = 0;
break;
}
}
}
int sum = 0;
for(int i = 1; i <= n;i++){
sum += b[i];
}
if(sum * 2 <= num) return true;
return false;
}
int main()
{
ios::sync_with_stdio(false);
while(cin >> n >> m){
for(int i = 1;i <= n;i++) cin >> a[i];
for(int i = 1;i <= m;i++){
int x,y; cin >> p[i].fi >> p[i].se;
}
ll ans = 1;
ll l = 1,r = 400000;
while(l <= r){
int mid = (l + r) / 2;
if(check(mid)){
ans = mid ;
r = mid - 1;
}else l = mid + 1;
}
wt(ans);
// cout << "dasda" << endl;
}
return 0;
}