A
题意
送老人过马路 没边都有 n个老人
贪心 先送还没开始送的老人
送完的时候发现时间是2nt 在 2号那边 这个时候 1号休息了 2nt-t 2号休息了 2nt-2t
等2号的话时间是 max(0,x-2nt+2t) 不等 2 号去接1号 是max(0,x-2nt)+t
接下来都不用等,直接送2nt
#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve()
{
int n,x,t;
cin>>n>>x>>t;
cout<<min(max(0ll,x-2*n*t)+t,max(0ll,x-2*n*t+2*t))+4*n*t<<"\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int _=1;
cin>>_;
while(_--)solve();
}
H
题意
加群 ,退群,发消息 ,维护个人与群的关系即可
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+5;
const int maxm=2*maxn;
map<int ,int>mm[maxn];
int a[maxn],b[maxm];
void solve()
{
for(int i=0;i<maxn;i++)
mm[i].clear(),a[i]=0,b[i]=0;
int n,m,s;
cin>>n>>m>>s;
for(int i=1;i<=s;i++)
{
int op,x,y;
cin>>op>>x>>y;
if(op==1)
{
mm[y][x]=1;
b[x]-=a[y];
}
else if(op==2)
{
mm[y][x]=0;
b[x]+=a[y];
}
else
{
a[y]++;
b[x]--;
}
}
for(int i=1;i<=n;i++)
{
for(auto m:mm[i])
{
if(m.second!=0)
b[m.first]+=a[i];
}
}
for(int i=1;i<=m;i++)
cout<<b[i]<<"\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int _=1;
//cin>>_;
while(_--)solve();
}
D
题意
给一个C
A+B=C
把ABC
质因数分解 乘积小于C yes 否则 no
不难发现如果 C的质因数分解 同一质因子有2个以上 他都可以拆分为小于C的
直接板子
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long LL;
ll n, Max = 0;
map<ll,int> mm;
inline ll mul(ll a, ll b, ll mod)
{
ll d = (long double)a / mod * b + 1e-8; //还必须是long double……double精度不够
ll r = a * b - d * mod;
return r < 0 ? r + mod : r;
}
inline ll quickpow(ll a, ll b, ll mod)
{
ll ret = 1;
for(; b; b >>= 1, a = mul(a, a, mod))
if(b & 1) ret = mul(ret, a, mod);
return ret;
}
inline bool test(ll a, ll d, ll n)
{
ll t = quickpow(a, d, n);
if(t == 1) return 1;
while(d != n - 1 && t != n - 1 && t != 1) t = mul(t, t, n), d <<= 1;
return t == n - 1; //这里就不用判1了,因为只可能在while前出现1的情况
}
int a[] = {2, 3, 5, 7, 11};
inline bool miller_rabin(ll n)
{
if(n == 1) return 0;
for(int i = 0; i < 5; ++i) //先粗筛一遍
{
if(n == a[i]) return 1;
if(!(n % a[i])) return 0;
}
ll d = n - 1;
while(!(d & 1)) d >>= 1;
for(int i = 1; i <= 5; ++i) //搞五遍
{
ll a = rand() % (n - 2) + 2;//x属于[2, n - 1]
if(!test(a, d, n)) return 0;
}
return 1;
}
inline ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
inline ll f(ll x, ll a, ll mod) {return (mul(x, x, mod) + a) % mod;}
const int M = (1 << 7) - 1; //我也不知道为啥M是这个数……
ll pollard_rho(ll n) //倍增版!减少gcd调用次数。(好像不用判环?)
{
for(int i = 0; i < 5; ++i) if(n % a[i] == 0) return a[i];
ll x = rand(), y = x, t = 1, a = rand() % (n - 2) + 2;
for(int k = 2;; k <<= 1, y = x)
{
ll q = 1;
for(int i = 1; i <= k; ++i)
{
x = f(x, a, n);
q = mul(q, abs(x - y), n);
// if(i >= M) //不等价!
if(!(i & M)) //超过了2 ^ 7,再用gcd
{
t = gcd(q, n);
if(t > 1) break; //找到了
}
}
if(t > 1 || (t = gcd(q, n)) > 1) break; //之所以再求一遍,是处理刚开始k < M的情况
}
return t;
}
LL factor[55],total=0;
inline void find(ll x)
{
if(x == 1 || x <= Max) return;
if(miller_rabin(x)) {factor[++total]=x; return;}
ll p = x;
while(p == x) p = pollard_rho(x);
//while(x % p == 0) x /= p;
find(p); find(x/p);
}
//int main(){
// long long x;
// scanf("%lld",&x);
// if (miller_rabin(x)){///质数
// cout<<x<<"is prime"<<endl;
// }
// else{///X是合数
// cout<<x<<"isn't prime"<<endl;
// memset(factor,0,sizeof(factor));
// total=0;
// find(x);
// sort(factor+1,factor+total+1);
// for(int i=1;i<=total;i++)
// cout<<factor[i]<<" ";
// cout<<endl;
// LL Primemin=factor[1];///最小质因子
// LL Primemax=factor[total];///最大质因子
// LL k=x/Primemin;///最大因数
// }
// return 0;
//}
void solve()
{
mm.clear();
ll c;
cin>>c;
if(miller_rabin(c))
{
cout<<"no"<<"\n";
return;
}
else
{
memset(factor,0,sizeof(factor));
total=0;
find(c);
//sort(factor+1,factor+total+1);
for(int i=1;i<=total;i++)
{
mm[factor[i]]++;
if(mm[factor[i]]>=2)
{
cout<<"yes"<<"\n";
return ;
}
}
cout<<"no"<<"\n";
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int _;
cin>>_;
while(_--)solve();
}