week 13

#include <bits/stdc++.h>

#define For(i, a, b) for (int i = a; i <= b; i++)

#define _For(i, a, b) for (int i = a; i >= b; i--)

typedef long long ll;

using namespace std;

const int maxn = 105, maxm = 1e5 + 5;

int n, m;

int f[maxn][maxm];

int main(){

ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

cin >> n >> m;

f[0][0] = 1;

For (i, 1, n) {

int t1, t2;

cin >> t1 >> t2;

For (j, 0, m) {

if (f[i - 1][j]) {

f[i][j + t1] = 1;

f[i][j + t2] = 1;

}

}

}

For (i, 0, m) {

if (f[n][i]) cout << 1; else cout << 0;

}

return 0;

}

#include <bits/stdc++.h>

#define For(i, a, b) for (int i = a; i <= b; i++)

#define _For(i, a, b) for (int i = a; i >= b; i--)

typedef long long ll;

using namespace std;

const int maxn = 5e5 + 5;

int n, t;

int a[maxn];

set <pair<int, int> > st;

int main(){

ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

cin >> n;

st.insert({2e9, 1});

For (i, 1, n) {

cin >> t;

auto iter = st.lower_bound({t, 0});

if (iter->second <= t) {

cout << t << " ";

if (iter->second <= t - 1)

st.insert({t - 1, iter->second});

if (t + 1 <= iter->first)

st.insert({iter->first, t + 1});

st.erase(iter);

} else {

cout << iter->second << " ";

if (iter->second + 1 <= iter->first)

st.insert({iter->first, iter->second + 1});

st.erase(iter);

}

}

return 0;

}

#include <bits/stdc++.h>

#define For(i, a, b) for (int i = a; i <= b; i++)

#define _For(i, a, b) for (int i = a; i >= b; i--)

typedef long long ll;

using namespace std;

ll n, k;

const int maxn = 1e5 + 5;

int a[maxn];

ll s[maxn];

int main(){

ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

cin >> n >> k;

For (i, 1, n) cin >> a[i], s[i] = s[i - 1] + a[i];

if (s[n] < k ) { puts("-1"); exit(0); }

ll l = 0, r = 1e9;

while (l + 1 < r) {

ll mid = l + r >> 1;

ll sum = 0;

For (i, 1, n) {

if (a[i] <= mid) sum += a[i];

else sum += mid;

}

if (sum > k) r = mid;

else l = mid;

}

ll sum = 0;

For (i, 1, n) {

if (a[i] <= l) sum += a[i];

else sum += l;

}

ll res = k - sum;

queue <int> q;

int cnt = 0;

For (i, 1, n) {

if (a[i] >= l + 1) {

if (cnt >= res) {

cout << i << " ";

}

else {

cnt++;

if (a[i] > l + 1)

q.push(i);

}

}

}

while (!q.empty()) {

cout << q.front() << " ";

q.pop();

}

return 0;

}

#include <bits/stdc++.h>

#define For(i, a, b) for (int i = a; i <= b; i++)

#define _For(i, a, b) for (int i = a; i >= b; i--)

typedef long long ll;

using namespace std;

const int maxn = 1e3 + 5;

struct node {

int s, e, w;

} a[maxn];

int f[maxn];

int n;

int main(){

ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

cin >> n;

For (i, 1, n) {

cin >> a[i].s >> a[i].e >> a[i].w;

}

sort(a + 1, a + 1 + n, [](node a, node b){

return (a.s < b.s || (a.s == b.s && a.e < b.e) || (a.s == b.s && a.e == b.e && a.w < b.w));

});

For (i, 1, n) f[i] = a[i].w;

For (i, 1, n) {

For (j, 1, i - 1) {

if (a[j].e <= a[i].s && f[j] + a[i].w > f[i]) {

f[i] = f[j] + a[i].w;

}

}

}

int ans = 0;

For (i, 1, n) {

ans = max(ans, f[i]);

}

cout << ans;

return 0;

}

#include <bits/stdc++.h>

#define For(i, a, b) for (int i = a; i <= b; i++)

#define _For(i, a, b) for (int i = a; i >= b; i--)

typedef long long ll;

using namespace std;

int n;

int main(){

ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

cin >> n;

For (i, 1, n) {

For (j, 1, n) {

For (l, 1, n) {

if (((i == l || i == n - l + 1) && (j >= l || j <= n - l + 1))

|| ((j == l || j == n - l + 1) && (i >= l || i <= n - l + 1)))

{

if (l % 2 == 1) cout << '+'; else cout << '.';

break;

}

}

}

cout << '\n';

}

return 0;

}

/*

板子题

*/

#include <bits/stdc++.h>

#define For(i, a, b) for (int i = a; i <= b; i++)

#define _For(i, a, b) for (int i = a; i >= b; i--)

typedef long long ll;

using namespace std;

const int maxn = 1e3 + 5;

int n;

int a[maxn], f[maxn];

int main(){

ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

cin >> n;

For (i, 1, n) cin >> a[i];

For (i, 1, n) f[i] = a[i];

For (i, 1, n) {

For (j, 1, i - 1) {

if (a[i] > a[j] && f[i] < f[j] + a[i]) f[i] = f[j] + a[i];

}

}

int ans = 0;

For (i, 1, n) {

ans = max(ans, f[i]);

}

cout << ans;

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值