M
解方程
void solve()
{
ll x,y; cin>>x>>y;
bool ok = false;
ll z = x * 1000 - y;
for(ll a = 0; a <= 1000000; a++)
{
ll t = a * 1000 - z;
if(t % 1500 == 0)
{
ll c = t / 1500;
ll b = x - a - c;
if(a >= 0 && b >= 0 && c >= 0 && a + b + c == x)
{
ok = true;
cout<<a<<" "<<b<<" "<<c<<endl;
break;
}
}
}
if(!ok)
cout<<-1<<endl;
}
C
思维,对角线放法,放一个对角线隔一列继续放对角线
void solve()
{
ll n, m;
cin>>n>>m;
ll ans = 0;
if(m > n)
swap(n, m);
ans = m + (n - m + 1) / 2;
cout<<ans<<endl;
}
H
首先观察到deg权值的数量很少,只需要记录deg权值为\(x\)的数量,再与其他权值\(x'\)做那个公式的值乘\(x\)的数量乘\(x'\)的数量即可
我的作法离散化了一下
typedef long long ll;
const ll mod = 998244353;
const int N = 1e6 + 10;
int n, m, cnt;
ll d[N];
vector<int> b;
map<int, int> mp;
ll s[4010];
ll val[4010][4010];
ll id[4000010];
void solve()
{
cin>>n>>m;
for(int i = 1; i <= m; i++)
{
int u, v; cin>>u>>v;
d[u]++, d[v]++;
}
for(int i = 1; i <= n; i++)
b.push_back(d[i]);
sort(b.begin(), b.end());
b.erase(unique(b.begin(), b.end()), b.end());
for(auto &it : b)
id[it] = ++cnt;
for(int i = 1; i <= n; i++)
s[id[d[i]]]++;
for(auto &it : b)
for(auto &its : b)
val[id[it]][id[its]] = (it ^ its) * (it | its) * (it & its);
ll ans = 0;
for(int i = 1; i <= cnt; i++)
for(int j = i + 1; j <= cnt; j++)
ans = (ans + ((val[i][j] * s[i] % mod) * s[j] % mod)) % mod;
cout<<ans<<endl;
}
J
思维,模拟,很快得到思路,但样例2看了半天,最后队友读出要满足前缀和\(pre_n \geq 0\)和\(a_1 \geq 0\),记维护前缀和的最大值\(\text{mav}\),对每个\(\text{resources} + a_i < 0\)给它加上前缀和最大值\(\text{mav}\)直到\(\text{resources} \geq 0\),我的第一发漏了考虑除0的情况,RE了一发
typedef long long ll;
const int mod = 998244353;
const int N = 1e5 + 10;
int n;
ll a[N], s[N], mav[N];
void solve()
{
cin>>n;
for(int i = 1; i <= n; i++)
cin>>a[i];
for(int i = 1; i <= n; i++)
s[i] = s[i - 1] + a[i];
if(a[1] < 0 || s[n] < 0)
{
cout<<-1<<endl;
return;
}
ll re = 0, ti = 0;
for(int i = 1; i <= n; i++)
{
mav[i] = max(mav[i - 1], s[i]);
if(re + s[i] >= 0)
re += s[i], ti++;
else
{
ll d = abs(re + s[i]);
if(mav[i] == 0)
{
cout<<-1<<endl;
return;
}
ll t = d / mav[i] + (d % mav[i] != 0);
re += t * mav[i] + s[i], ti += t + 1;
}
}
cout<<ti<<endl;
}
F
队友读的,发现是个简单题,他说我写
对于每个回文半径把左区间copy给右区间
char op[N];
int a[N];
void solve()
{
int n; cin>>n;
int m = 2 * n + 2;
for(int i = 1; i <= m; i++)
{
cin>>a[i];
}
op[0] = '?', op[1] = '&', op[2] = '|', op[3] = 'a';
for(int i = 4; i <= m; i++)
{
op[i] = '|';
if(a[i] == 1)
{
if(op[i - 1] == 'a')
op[i + 1] = 'b';
else
op[i + 1] = 'a';
i++;
}
else
{
for(int r = 1; r <= a[i] - 2; r++)
op[i + r] = op[i - r];
i = i + a[i] - 2;
}
}
for(int i = 1; i <= 2 * n + 2; i++)
if(op[i] == 'a' || op[i] == 'b')
cout<<op[i];
cout<<endl;
}
标签:int,ll,cin,湖北省,solve,2023,void,op
From: https://www.cnblogs.com/magicat/p/17380089.html