A模拟
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 1e5 + 5;
char s[N];
void solve()
{
scanf("%s",s + 1);
int n = 10;
int a = 0,b = 0;
for(int i = 1;i <= n;i ++){
if(i % 2 == 1){
if(s[i] == '1') a ++;
}
else if(s[i] == '1') b ++;
int sa = 0,sb = 0;
for(int j = i + 1;j <= n;j ++)
if(j % 2 == 1) sa ++;
else sb ++;
if(a > sb + b || b > sa + a) {
printf("%d\n",i);
return ;
}
}
printf("-1\n");
}
int main()
{
int t;
cin >> t;
while (t -- ) solve();
}
C 贪心
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 3e5 + 5;
int a[N];
void solve()
{
int n;
cin >> n;
int ans = 0;
for (int i = 1; i <= n; i ++ ) {
cin >> a[i];
if(a[i] > 0) ans ++;
}
cout << ans << endl;
}
int main()
{
int t;
cin >> t;
while (t -- ) solve();
}
D 结论题 枚举四个顶点算答案即可
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
void solve()
{
double x,y,a,b;
cin >> x >> y >> a >> b;
double ans = 0;
double s = x * y;
if(a <= x && b <= y){
ans = max(ans,(x - a) * (y - b)/s);
ans = max(ans,(x - a) * b/s);
ans = max(ans,a * (y - b)/s);
ans = max(ans,a * b/s);
}
else if(a <= x && b > y){
ans = max(ans,a * y / (s + a * (b - y)));
ans = max(ans,(x - a) * y / (s + (x - a) * (b - y)));
}else if(a >= x && b < y){
ans = max(ans, (x * b) / (s + (a - x) * b ));
ans = max(ans, (x * (y - b)) / (s + (a - x) * (y - b)));
}else
ans = x * y / (s + (a - x) * y + (b - y) * x + (a - x) * (b - y));
printf("%.6lf\n",ans);
}
int main()
{
int t;
cin >> t;
while (t -- ) solve();
}
F 待补
G 暴力线段树
先打表,发现每一个数的变化情况后面都会趋于三个数 0 99 100
直接维护 每一段的0,99,100的个数
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 1e5 + 5;
LL a[N];
struct Node{
int l,r;
LL sum;
int cnt1;
int cnt0;
int cnt9;
}tr[N << 2];
int n,m;
void pushup(int u)
{
tr[u].sum = tr[u << 1].sum + tr[u << 1 | 1].sum;
tr[u].cnt1 = tr[u << 1].cnt1 + tr[u << 1 | 1].cnt1;
tr[u].cnt9 = tr[u << 1].cnt9 + tr[u << 1 | 1].cnt9;
tr[u].cnt0 = tr[u << 1].cnt0 + tr[u << 1 | 1].cnt0;
}
void build(int u,int l,int r)
{
if(l == r) {
tr[u] = {l,r,a[l],0,0,0};
if(a[l] == 0) tr[u].cnt0 = 1;
if(a[l] == 100) tr[u].cnt1 = 1;
if(a[l] == 99) tr[u].cnt9 = 1;
}
else{
tr[u] = {l,r};
int mid = l + r >> 1;
build(u << 1,l,mid);
build(u << 1 | 1,mid + 1,r);
pushup(u);
}
}
void modify(int u, int l, int r,int k) {
if (tr[u].sum == 0) return;
if (tr[u].cnt9 + tr[u].cnt1 + tr[u].cnt0 == tr[u].r - tr[u].l + 1) return;
if (tr[u].l == tr[u].r) {
while(k --)
{
tr[u].sum = round(10 * sqrt(tr[u].sum));
if(tr[u].sum == 99) {
tr[u].cnt9 = 1;
break;
}
if(tr[u].sum == 100){
tr[u].cnt1 = 1;
break;
}
if(tr[u].sum == 0){
tr[u].cnt0 = 1;
break;
}
}
return;
}
int mid = tr[u].l + tr[u].r >> 1;
if (l <= mid) modify(u << 1, l, r,k);
if (r > mid) modify(u << 1 | 1, l, r,k);
pushup(u);
}
LL query(int u,int l,int r)
{
if(tr[u].l >= l && tr[u].r <= r) return tr[u].sum;
else {
LL ans = 0;
int mid = tr[u].l + tr[u].r >> 1;
if(l <= mid) ans = query(u << 1,l,r);
if(r > mid) ans += query(u << 1 | 1,l,r);
return ans;
}
}
int main()
{
scanf("%d %d", &n,&m);
for(int i = 1;i <= n;i ++) scanf("%lld",&a[i]);
build(1,1,n);
while(m --)
{
int op,l,r,k;
scanf("%d",&op);
if(op == 2) printf("%lld\n",query(1,1,n));
else {
scanf("%d %d %d",&l,&r,&k);
modify(1,l,r,k);
}
}
return 0;
}
H 思维
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
void solve()
{
int n;
cin >> n;
int ans = 10;
for(int i = 1;i <= n * n - 1;i ++) {
string s;
cin >> s;
for(int i = 0;i < s.size();i ++)
if(s[i] == '2' ) ans --;
else if(s[i] == '1') ans ++;
}
cout << ans << endl;
}
int main()
{
int t;
cin >> t;
while(t --) solve();
return 0;
}
K 状态压缩DP(状态机DP)
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 1005;
int dp[N][N][4];
// 00 0
// 01 1
// 10 2
// 11 3
void solve()
{
int n,m;
cin >> n >> m;
memset(dp, 0x3f, sizeof dp);
for(int i = 1;i <= 2;i ++)
for(int j = 0;j <= i;j ++)
{
dp[i][0][0] = 0;
if(j == 1) dp[i][1][1] = dp[i][1][2] = 0;
if(j == 2) dp[i][j][3] = 0;
}
for(int i = 3;i <= n;i ++)
for(int j = 1;j <= m;j ++)
{
dp[i][j][0] = min(dp[i - 1][j][0],dp[i - 1][j][2]);
dp[i][j][1] = min(dp[i - 1][j - 1][2] + 1,dp[i - 1][j - 1][0]);
dp[i][j][2] = min(dp[i - 1][j][1],dp[i - 1][j][3] + 1);
dp[i][j][3] = min(dp[i - 1][j - 1][3],dp[i - 1][j - 1][1]) + 1;
}
int ans = 0x3f3f3f3f;
for(int i = 0;i <= 3;i ++)
ans = min(ans,dp[n][m][i]);
cout << ans << endl;
}
int main()
{
int t;
//cin >> t;
t = 1;
while (t -- ) solve();
}
L数学
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 1005;
int dp[N][N][4];
// 00 0
// 01 1
// 10 2
// 11 3
void solve()
{
cout << 32 << endl;
}
int main()
{
int t;
//cin >> t;
t = 1;
while (t -- ) solve();
}
M DP
一开始以为是贪心寄了,
这种情况发现数据比较小的情况应该往DP考虑考虑,弄出所有的情况
DP比较基础
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
void solve()
{
int n,m;
cin >> n >> m;
double ans = 0;
if(m > n) ans += (double)(m - n + 1) / m,m -= (m - n + 1);
m ++;
while (m --){
if(m == 0) break;
ans += (double)1/m;
}
printf("%.8lf",ans);
}
int main()
{
int t;
t = 1;
while (t -- ) solve();
}