#include
#define fi first
#define se second
#define int long long
#define pb push_back
#define endl '\n'
#define all(x) x.begin(),x.end()
#define PII pair<int,int>
using namespace std;
const int N = 2e5 + 100,mod=998244353;
bool st[10][10];
void solve()
{
int n,m; cin >> n >> m;
for(int i = 1;i <= m;i ++ )
{
int x,y; cin >> x >> y;
}
if(m >= n) cout << "NO" << endl;
else cout << "YES" << endl;
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T; cin >> T;
while(T -- ) solve();
}
#include
#define fi first
#define se second
#define int long long
#define pb push_back
#define endl '\n'
#define all(x) x.begin(),x.end()
#define PII pair<int,int>
using namespace std;
const int N = 2e5 + 100,mod=998244353;
bool st[10][10];
void solve()
{
int n,m; cin >> n;
int sum = 0;
for(int i = 1;i <= n;i ++ )
{
int x;
cin >> x;
sum += x;
}
int mx = -1;
for(int i = 1;i <= n;i ++ )
{
int x; cin >> x;
mx = max(mx,x);
sum += x;
}
cout << sum - mx << endl;
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T; cin >> T;
while(T -- ) solve();
}
思路: A操作越多,能够选择的数字越少,所以贪心来看,就让A尽量选择大的删除,同时B为了不让A操作过多,贪心来看,就尽量在元素值小的地方加上去,这样给a数组排序,因为k最大是(n + 1) / 2,n <= 100,所以直接暴力枚举k的取值,当然二分也行,然后看看在当前的k下,是否满足条件
代码:
#include
#define fi first
#define se second
#define int long long
#define pb push_back
#define endl '\n'
#define all(x) x.begin(),x.end()
#define PII pair<int,int>
using namespace std;
const int N = 2e5 + 100,mod=998244353;
int a[110];
void solve()
{
int n,m; cin >> n;
int d = 0; // k最大是n + 1 / 2;
for(int i = 1;i <= n;i ++ ) cin >> a[i];
sort(a + 1,a + 1 + n);
for(int k = (n + 1) / 2;k >= 1;k -- )
{
int u = k;
int d = 0;
int i = 1,j = n;
while(i <= j)
{
while(j >= i && a[j] > u) j--;
if(j >= i && a[j] <= u)
{
d++;
j--;
}
else
break;
u--;
i++;
}
if(d >= k)
{
cout << k << endl;
return;
}
}
cout << "0" << endl;
//如果数组中没有1,那就是0
// 如果有1个1,答案就是1
// 如果有两个1,答案就是2
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T; cin >> T;
while(T -- ) solve();
}
#include
#define int long long
#define PII pair<int,int>
using namespace std;
const int N = 2e5 + 100,mod = 998244353;
int p[N],cnt;
bool st[N];
void init()
{
for(int i = 2;i <= N;i ++ )
{
if(!st[i])
p[cnt++] = i;
for(int j = 0;p[j] <= N / i;j ++ )
{
st[i * p[j]] = true;
if(i % p[j] == 0) break;
}
}
}
int quick(int a,int b)
{
int k = 1;
a %= mod;
while(b)
{
if(b & 1)
{
k = k * a % mod;
}
b = b >> 1;
a = a * a % mod;
}
return k;
}
void solve()
{
int n,m; cin >> n >> m;
int tmp = 1;
int w = m % mod,res =0;
int y = m % mod;
for(int i = 2;i <= n;i ++ ) // 要知道每一个a[i],有多少种选法使得
{
if(!st[i] && tmp <= m) // 质数
tmp = tmp * i;
w = (w * ((m / tmp) % mod)) % mod; // 不超过1e12
res = (res + w) % mod;
}
int ans = 0;
for(int i = 2;i <= n;i ++ )
ans = (ans + quick(m,i)) % mod;
cout << (ans + mod - res) % mod<< endl;
}
signed main()
{
init();
int T = 1;
while(T -- ) solve();
return 0;
}
#include
#define int long long
#define pb push_back
#define fi first
#define se second
#define ios ios::sync_with_stdio(false),cin.tie(0)
#define PII pair<int,int>
using namespace std;
const int N = 4e5 + 100,mod = 1e9 + 7,INF = 1e9;
int n,m;
int dx[4] = {-1, -1, 1, 1}, dy[4] = {-1, 1, -1, 1};
bool check(string *s,int x,int y)
{
if(x < 1 || x > n || y < 1 || y > m) return false;
if(x + 1 <= n && s[x + 1][y] == '#') return false;
if(x - 1 >= 1 && s[x - 1][y] == '#') return false;
if(y + 1 <= m && s[x][y + 1] == '#') return false;
if(y - 1 >= 1 && s[x][y - 1] == '#') return false;
return true;
}
void solve()
{
cin >> n >> m;
string s[n + 1];
for(int i = 1;i <= n;i ++ ) cin >> s[i],s[i] = "?" + s[i];
deque<PII> q;
vector<vector<PII> > pre(n + 2,vector<PII> (m + 2));
vector<vector<int> > dist(n + 2,vector<int> (m + 2,INF));
for(int i = 1;i <= n;i ++ )
{
if(s[i][1] == '#') // 权值为0
{
dist[i][1] = 0;
q.push_front({i,1});
}
else if(check(s,i,1))
{
dist[i][1] = 1;// 权值为1
q.push_back({i,1});
}
}
while(q.size())
{
auto t = q.front();q.pop_front();
for(int i = 0;i < 4;i ++ )
{
int x = dx[i] + t.fi,y = dy[i] + t.se;
if(check(s,x,y)) // 代表当前这个点能走
{
if(dist[t.fi][t.se] + (s[x][y] != '#') < dist[x][y])
{
pre[x][y] = {t.fi,t.se};// 记录前驱
dist[x][y] = dist[t.fi][t.se] + (s[x][y] != '#');
if(s[x][y] == '#')
q.push_front({x,y});
else
q.push_back({x,y});
}
}
}
}
// 寻找前驱
int x = 0,y = 0;
int ans = INF;
for(int i = 1;i <= n;i ++ )
{
if(ans > dist[i][m])
{
ans = dist[i][m];
x = i,y = m;
}
}
if(ans == INF) cout << "NO" << endl;
else
{
cout << "YES" << endl;
while(1)
{
if(s[x][y] == '.') s[x][y] = '#';
if(y == 1) break;
auto p = pre[x][y];
x = p.fi;
y = p.se;
}
for(int i = 1;i <= n;i ++ )
{
for(int j = 1;j <= m;j ++ )
cout << s[i][j];
cout << endl;
}
}
}
signed main()
{
ios; int T; cin >> T;
while(T -- ) solve();
return 0;
}