T639096 落落的去养植物
思路
简单模拟
正确代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll s = 0, c = 0, h;
cin >> h;
while(s <= h){
s += pow(2, c);
c++;
}
cout << c;
return 0;
}T638488 数字存储
思路
进制
正确代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll s;
cin >> s;
ll cnt = 1;
for(int i = 1; i <= s; i++){
int k = i;
while(k){
cnt++;
k /= 2;
}
}
cout << cnt;
return 0;
}T638482 小梦的铁索连环
思路
图的DFS,在加入新的点是判断他是否与所有已加入的点相连
正确代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, m, a[501], b[501], ans = -1e18;
bool vis[501];
int g[501][501];
void dfs(int step, int sum){
ans = max(ans, sum);
for(int i = 1; i <= n; i++){
if(vis[i]){
continue;
}
bool flag = 1;
for(int j = 1; j < step; j++){
int v = b[j];
if(g[i][v] == 0){
flag = 0;
break;
}
}
if(flag){
vis[i] = 1;
b[step] = i;
dfs(step + 1, sum + a[i]);
vis[i] = 0;
}
}
return;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= m; i++){
int x, y;
cin >> x >> y;
g[x][y] = 1, g[y][x] = 1;
}
dfs(1, 0);
cout << ans;
return 0;
}T638458 忙碌的老师
思路
不相交区间分组问题板子
正确代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int b[100001], c[100001], o[100001];
struct Node{
int l, r;
} a[100001];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i].l >> a[i].r;
b[i] = a[i].l, c[i] = a[i].r;
}
stable_sort(b + 1, b + n + 1);
stable_sort(c + 1, c + n + 1);
int cnt = 0, l = 2, cc = 0;
cnt++;
o[cnt] = 1;
cc++;
while(l <= n){
int flag = 0;
if(cnt != 0){
for(int i = 1; i <= cc; i++){
if(c[o[i]] < b[l]){
flag = i;
break;
}
}
}
if(!flag){
cnt++;
o[cnt] = l;
cc++;
}else{
o[flag] = l;
}
l++;
}
cout << cnt;
return 0;
}