安(对面对攻击)
看当前人有几个比对面大的,这些肯定可行
如果相等就对半开。上取整
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+100;
int n;
int a[N],b[N];
void Work(){
cin>>n;
for (int i = 1; i <= n; i++) cin>>a[i]; for (int j = 1; j <= n; j++) cin>>b[j];
int cnt1 = 0 , cnt2 = 0;
for (int i = 1; i <= n; i++)
if (a[i] > b[i]) cnt1++;
else if (a[i] == b[i]) cnt2++;
if (cnt2 % 2 == 1) cnt2 = cnt2/2+1; else cnt2 = cnt2/2;
cout<<cnt1+cnt2<<endl;
return ;
}
int main(){
int t; cin>>t; while (t--) Work();
return 0;
}
知(若干个数,乘积最大)
从前往后遍历,如果当前的数比后面的小,就调整到两个数的绝对值不超过1(前面大于等于后面)
不断纠正,直到不可纠正为止
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int P = 998244353;
int n;
int a[1000];
void Work(){
cin>>n;
for (int i = 1; i <= n; i++) cin>>a[i];
while (1){
bool f = 0;
for (int i = 1; i < n; i++){
int del = a[i+1]-a[i];
if (del <= 0) continue;
int x = a[i+1]+a[i];
if (x%2) a[i] = x/2+1,a[i+1] = x/2;
else a[i] = x/2,a[i+1]=x/2;
f = 1;
}
if (f == 0) break;
}
int s = 1;
for (int i = 1; i <= n; i++) s = s*a[i]%P;
cout<<s<<endl;
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
int t; cin>>t; while (t--) Work();
return 0;
}
珑(骨牌)
分类讨论结论题
要讨论全
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,a,b,T;
bool ans;
bool solve(){
scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
if ((n*m)%2ll==1ll){
return false;
}
if (a==1ll&&b==1ll)return true;
if (a==1ll&&b==0ll){
if (n==1ll&&m%2ll==0ll)return true;
if (m==1ll&&n%2ll==0ll)return true;
return false;
}
if (a==0ll&&b==1ll){
if ((n%2ll==0ll&&m>1)||(m%2ll==0ll&&n>1ll))return true;
if ((n==2ll&&m==1ll)||(m==2ll&&n==1ll))return true;
return false;
}
if (a==0ll&&b==0ll){
if (n==1ll&&m==2ll)return true;
if (n==2ll&&m==1ll)return true;
return false;
}
return false;
}
signed main(){
scanf("%lld",&T);
while (T--){
ans=solve();
if (ans)printf("Yes\n");
else printf("No\n");
}
return 0;
}
入(包搜)
爆搜即可
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8, pi = acos(-1.0);
int n, m, ans, p[45];
vector<int> linker[45];
PII vis[45];
void dfs(int u, int deep, int last)
{
ans = max(ans, deep);
for (int i = 0; i < linker[u].size(); i++)
{
int v = linker[u][i];
if (!vis[v].first)
{
for (int j = 0; j < linker[u].size(); j++)
if (!vis[linker[u][j]].first)
vis[linker[u][j]].first = 1, vis[linker[u][j]].second = u;
// vis[v] = 1;
// p[deep + 1] = v;
dfs(v, deep + 1, u);
// vis[v] = 0;
for (int j = 0; j < linker[u].size(); j++)
{
if (linker[u][j] == last)
continue;
if (vis[linker[u][j]].second == u)
vis[linker[u][j]].first = 0, vis[linker[u][j]].second = 0;
}
}
}
// for (int i = 1; i <= deep; i++)
// cout << p[i] << ' ';
// cout << endl;
}
void solve()
{
ans = 0;
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
int u, v;
cin >> u >> v;
linker[u].push_back(v);
linker[v].push_back(u);
}
for (int i = 1; i <= n; i++)
{
vis[i].first = 1;
// cout << i << ' ';
// p[1] = i;
dfs(i, 1, 0);
vis[i].first = 0;
// cout << endl;
}
cout << ans;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("D:/in.txt", "r", stdin);
freopen("D:/out.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
solve();
return 0;
}
先写这些,后续的后面补上