A. Deadline
x
+
⌈
d
x
+
1
⌉
x + \lceil \frac{d}{x + 1} \rceil
x+⌈x+1d⌉ 我们就可以想到基本不等式,即取x/2时不等式取到最大值,于是就可以得出答案。
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
int T;scanf("%d",&T);
while(T--){
ll d,n;scanf("%lld %lld",&n,&d);
if(n & 1) n = (n / 2 + 1) * (n / 2 + 1);
else n = (n / 2) * (n / 2 + 1);
if(n >= d) puts("YES");
else puts("NO");
}
}
B. Yet Another Meme Problem
遇事不决先打表,很容易发现只有m为9,99,999,9999,并且n<=m时成立,于是就。。。。
#include<bits/stdc++.h>
using namespace std;
int main(){
int T;
scanf("%d",&T);
while(T--){
ll n,m;scanf("%lld %lld",&n,&m);
ll ans = 0,res = 1;
for(int i = 1;;i++){
res *= 10;
if(res - 1 <= m) ans++;
else break;
}
printf("%lld\n",ans * n);
}
}
C. Two Arrays
给你n个数,m个位置,排成两个序列,一个不递减,一个不递增,问你一共有几中组合方式。
那我用dp[i][j] 表示i位长的串以j结尾的个数,起点为dp[0][n - 1],那前一位对后一位的贡献就是dp[i + 1][k] += dp[i][j] * (j - k + 1),结束得值为dp[m][0~n];
#include<bits/stdc++.h>
typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 1e6 + 5;
const int maxm = 1e5 + 10;
const int mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-6;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline ll readll(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
ll eular(ll n){ll ans = n;for(int i = 2; i*i <= n; i++){if(n % i == 0){ans -= ans/i;while(n % i == 0) n /= i;}}if(n > 1)ans -= ans/n; return ans;}
ll qpow(ll a, ll n){ll ans = 1;while(n){if(n&1){ans = (ans * a) % mod;}a = (a * a) % mod;n >>= 1;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}
using namespace std;
ll dp[11][1010];
int main(){
int n,m;scanf("%d %d",&n,&m);
dp[0][n - 1] = 1;
for(int i = 0;i < m;i++){
for(int j = 0;j <= n;j++){
ll res = 1;
for(int k = j;k >= 0;k--){
dp[i + 1][k] += dp[i][j] * res % mod;
dp[i + 1][k] %= mod;
res++;
}
}
}
ll ans = 0;
for(int i = 0;i <= n;i++) ans += dp[m][i],ans %= mod;
printf("%lld\n",ans);
}
D. Minimax Problem
给你n行,每行m个数,让你选出任意两行,使得两行组合后得最小值最大。组合得定义给同一列取较大得那个数。
因为m只有8,考虑二分答案,check中,将每行所有得情况全部暴力计算出来,然后对于这些情况
(
(
1
<
<
m
)
−
1
)
2
((1 <<m ) - 1)^2
((1<<m)−1)2得复杂度暴力计算出来就好了,判断条件为
(
(
i
∣
j
)
=
=
(
(
1
<
<
m
)
−
1
)
)
((i | j) == ((1 << m )- 1))
((i∣j)==((1<<m)−1))。
#include<bits/stdc++.h>
#define accept return 0
#define mes(a, b) memset(a, b, sizeof a)
typedef unsigned long long int ull;
typedef long long int ll;
const int maxn = 3e5 + 5;
const int maxm = 1e5 + 10;
const int mod = 1e9 + 7;
const ll INF = 1e18 + 100;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-6;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
inline ll readll(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
ll eular(ll n){ll ans = n;for(int i = 2; i*i <= n; i++){if(n % i == 0){ans -= ans/i;while(n % i == 0) n /= i;}}if(n > 1)ans -= ans/n; return ans;}
ll qpow(ll a, ll n){ll ans = 1;while(n){if(n&1){ans = (ans * a) % mod;}a = (a * a) % mod;n >>= 1;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}
using namespace std;
int ans1,ans2;
int used[500];
int tot;
int n,m;
int mp[maxn][20];
bool check(int pos){
for(int i = 0;i <= tot;i++) used[i] = 0;
for(int i = 1;i <= n;i++){
int tmp = 0;
for(int j = 1;j <= m;j++){
if(mp[i][j] >= pos) tmp = tmp << 1 | 1;
else tmp = tmp << 1;
}
used[tmp] = i;
}
for(int i = 0;i <= tot;i++) for(int j = 0;j <= tot;j++){
if((i | j) == (tot) && used[i] && used[j]){
ans1 = used[i];ans2 = used[j];
return true;
}
}
return false;
}
int main(){
scanf("%d %d",&n,&m);
tot = (1 << m) - 1;
for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++){
scanf("%d",&mp[i][j]);
}
int l = 0,r = 1e9,ans = 0;
while(l <= r){
int mid = l + r >> 1;
if(check(mid)) ans = mid,l = mid + 1;
else r = mid - 1;
}
printf("%d %d\n",ans1,ans2);
}