A - Long Comparison
B - Absent Remainder
C - Poisoned Dagger
D - MEX Sequences
E - Crazy Robot
拿字符串比较
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <set>
#define mid (l+r>>1)
#define lowbit(x) (x&-x)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 2e6+10, mod = 1e9 + 7;
void mull(int &a, LL b){a = a*b%mod;return ;}
void add(int &a, LL b){a = (a+b)%mod;return ;}
int main()
{
int t;
scanf("%d", &t);
while(t --)
{
string a, b;
int c, d, f = 1;
cin>>a>>c>>b>>d;
while(a.size()<b.size()&&c)a+='0', c--;
while(a.size()>b.size()&&d)b+='0', d--;
int la = a.size()+c, lb = b.size()+d;
if(la < lb) f = -1;
else if(la == lb)
{
if(a == b)f = 0;
else if(a > b)f = 1;
else f = -1;
}
if(f == 1)puts(">");
else if(f == -1)puts("<");
else puts("=");
}
return 0;
}
y m o d x = t , i f y > x , t < x y\,mod\,x = t, \,if y > x,t < x ymodx=t,ify>x,t<x,那么x取最小值
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <set>
#define mid (l+r>>1)
#define lowbit(x) (x&-x)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 2e6+10, mod = 1e9 + 7;
void mull(int &a, LL b){a = a*b%mod;return ;}
void add(int &a, LL b){a = (a+b)%mod;return ;}
int a[N];
int main()
{
int t;
scanf("%d", &t);
while(t --)
{
int n;
scanf("%d", &n);
for(int i = 0;i < n;i ++)scanf("%d", a+i);
sort(a, a+n);
int len = n/2, x = 1;
while(len --)
printf("%d %d\n", a[x++], a[0]);
}
return 0;
}
答案具有单调性,那么可以二分 n l o g n nlog\,n nlogn
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <set>
#define mid (l+r>>1)
#define lowbit(x) (x&-x)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 2e6+10, mod = 1e9 + 7;
void mull(int &a, LL b){a = a*b%mod;return ;}
void add(int &a, LL b){a = (a+b)%mod;return ;}
int a[N], n;
LL h;
bool ch(LL x)
{
LL sum = 0, tail = 0;
for(int i = 1;i <= n;tail = max(tail, a[i]+x), i ++)
tail < a[i] ? sum += x : sum += a[i]+x-tail;
return sum >= h;
}
int main()
{
int t;
scanf("%d", &t);
while(t --)
{
scanf("%d%lld", &n, &h);
for(int i = 1;i <= n;i ++)scanf("%d", a+i);
LL l = 1, r = 1e18;
while(l < r)
{
if(ch(mid))r = mid;
else l = mid+1;
}
cout<<l<<endl;
}
return 0;
}
d p , d p [ i ] [ 0 / 1 ] 表 示 m e x = i , m a x = i − 1 o r i + 1 dp,dp[i][0/1] 表示mex = i,max = i-1\,or\,i+1 dp,dp[i][0/1]表示mex=i,max=i−1ori+1 然后开始疯狂的推式子了, a i 会 和 d p [ a i − 1 ] , d p [ a i ] , d p [ a i + 1 ] a_i会和dp[a_i-1],dp[a_i],dp[a_i+1] ai会和dp[ai−1],dp[ai],dp[ai+1] 有影响,我把所有的数字都右移了1,因为不移1的话初始状态是 d p [ − 1 ] [ 1 ] = 1 dp[-1][1]=1 dp[−1][1]=1
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <set>
#define mid (l+r>>1)
#define lowbit(x) (x&-x)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 2e6+10, mod = 998244353;
void mull(int &a, LL b){a = a*b%mod;return ;}
void add(int &a, LL b){a = (a+b)%mod;return ;}
int in[N], dp[N][2];
int main()
{
int t;
scanf("%d", &t);
while(t --)
{
int n;
scanf("%d", &n);
int ans = 0;
dp[1][0] = 1;
for(int i = 1;i <= n;i ++)
{
int x;
scanf("%d", &x); ++x;
add(ans, (LL)dp[x+1][0]+dp[x+1][1]+dp[x][0]+dp[x-1][1]+dp[x-1][0]);
add(dp[x-1][1], dp[x-1][1] + dp[x-1][0]);
mull(dp[x+1][1], 2);
add(dp[x+1][0], dp[x+1][0] + dp[x][0]);
}
for(int i = 1;i <= n+1;i ++)
dp[i][0] = dp[i][1] = 0;
cout<<ans<<endl;
}
return 0;
}
这题想简单了,哎。要边遍历边修改
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#define mid (l+r>>1)
#define lowbit(x) (x&-x)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 1e6+10, mod = 998244353;
void mull(int &a, LL b){a = a*b%mod;return ;}
void add(int &a, LL b){a = (a+b)%mod;return ;}
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
int main()
{
int t;
scanf("%d", &t);
while(t --)
{
int n, m, x, y;
scanf("%d%d", &n, &m);
char a[n+1][m+1] ;
for(int i = 1;i <= n;i ++)
{
scanf("%s", a[i]+1);
for(int j = 1;j <= m;j ++)
if(a[i][j] == 'L')
x = i, y = j;
}
queue<PII>q;
while(!q.empty())q.pop();
for(int i = 0;i < 4;i ++)
q.push({x+dx[i], y+dy[i]});
a[x][y] = '+';
while(!q.empty())
{
int x = q.front().first, y = q.front().second, l = 0, r = 0;
q.pop();
if(!x || x>n || !y || y>m || a[x][y] != '.') continue;
for(int i = 0;i < 4;i ++)
{
int ll = x+dx[i], rr = y+dy[i];
if(!ll || ll>n ||!rr || rr>m)continue;
l += a[x+dx[i]][y+dy[i]] == '.', r += a[x+dx[i]][y+dy[i]] == '+';
}
if(!r || l > 1 )continue;
a[x][y] = '+';
for(int i = 0;i < 4;i ++)
q.push({x+dx[i], y+dy[i]});
}
a[x][y] = 'L';
for(int i = 1;i <= n;i ++)
printf("%s\n",a[i]+1);
}
return 0;
}
//#....
//..##L
//...#.
//.....