A.牛牛去购物(背包dp)
n元钱买a/b最少剩余,由于n<=1000,用背包即可,复杂度O(n)
#include
#define ll long long
#define ls p<<1
#define rs p<<1|1
#define Ma 1000005
#define mod 1000000007
#define PLL pair
#define PDD pair
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define N 61
#define pb push_back
#define ld long double
using namespace std;
ll n,a,b;
ll f[Ma];
void sol()
{
scanf("%lld%lld%lld",&n,&a,&b);
f[0]=1;
ll ma=0;
for (ll i=1;i<=n;i++)
{
if (i>=a&&f[i-a])
f[i]=1;
if (i>=b&&f[i-b])
f[i]=1;
if (f[i])
ma=i;
}
printf("%lld\n",n-ma);
return;
}
int main()
{
sol();
return 0;
}
B.牛牛写情书(暴力)
暴力匹配字符串即可,注意特殊字符串的实现
#include
#define ll long long
#define ls p<<1
#define rs p<<1|1
#define Ma 1000005
#define mod 1000000007
#define PLL pair
#define PDD pair
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define N 61
#define pb push_back
#define ld long double
using namespace std;
ll n,m;
ll a[Ma];
string p="0123456789+-*|,.~!@#$%^&()[]{}'\";:?<>\\/";
map mp;
void sol()
{
cin>>n>>m;
for (ll i=0;i>s>>t;
ll flag=0;
for (ll i=0;i
C.牛牛排队伍(摸你)
记录怕热和nex即可
#include
#define ll long long
#define ls p<<1
#define rs p<<1|1
#define Ma 1000005
#define mod 1000000007
#define PLL pair
#define PDD pair
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define N 61
#define pb push_back
#define ld long double
using namespace std;
ll n,m;
ll f[Ma],ne[Ma];
void sol()
{
scanf("%lld%lld",&n,&m);
for (ll i=1;i<=n;i++)
f[i]=i-1,ne[i]=i+1;
for (ll i=1;i<=m;i++)
{
ll op,x;
scanf("%lld%lld",&op,&x);
if (op==1)
{
ll px=f[x],py=ne[x];
ne[px]=py,f[py]=px;
}
else
printf("%lld\n",f[x]);
}
return;
}
int main()
{
sol();
return 0;
}
D.牛牛取石子(博弈+思维)
对于a=b的部分,我们发现a%3==2的情况才可以赢
对于a!=b的部分,题目变为min(a,b)取1/2的取石子博弈。
#include
#define ll long long
#define ls p<<1
#define rs p<<1|1
#define Ma 1000005
#define mod 1000000007
#define PLL pair
#define PDD pair
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define N 61
#define pb push_back
#define ld long double
using namespace std;
ll a,b;
void sol()
{
scanf("%lld%lld",&a,&b);
if (a>b)
swap(a,b);
if (a==b)
{
if (a%3==2)
printf("niuniu\n");
else
printf("niumei\n");
}
else
{
if (a%3==0)
printf("niumei\n");
else
printf("niuniu\n");
}
return;
}
int main()
{
ll tt;
scanf("%lld",&tt);
while (tt--)
sol();
return 0;
}
E.牛牛的构造(贪心+构造)
我们发现对于一个数x来说,对其有影响的数字为x+(),因此我们能够很容易发现其,而对于删除点我们需从大到小删除。
证明:对于其贡献值序列以以下形式呈现:0,1,2,2,3,3,3,3,4,4......,保证了可行性。
PS:写代码的时候i,j顺序写反了,所以GGGGGGGGGGGGGG
#include
#define ll long long
#define ls p<<1
#define rs p<<1|1
#define Ma 1000005
#define mod 1000000007
#define PLL pair
#define PDD pair
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define N 61
#define pb push_back
#define ld long double
using namespace std;
ll n,k;
ll a[Ma],f[Ma];
ll w[Ma];
ll tot;
ll get(ll x)
{
x=n-x;
ll g=1,ans=0;
while (g<=x)
g<<=1,ans++;
return ans;
}
void sol()
{
scanf("%lld%lld",&n,&k);
tot=n;
ll ma=0;
for (ll i=1;i<=n;i++)
w[i]=get(i),ma+=w[i];
k=ma-k;
if (k<0)
{
printf("-1\n");
return;
}
for (ll i=1;i<=n;i++)
if (k>=w[i])
{
k-=w[i];
f[i]=1;
a[tot--]=i;
}
ll p=0;
for (ll i=1;i<=n;i++)
if (!f[i])
a[++p]=i;
for (ll i=n;i>=1;i--)
printf("%lld ",a[i]);
return;
}
int main()
{
sol();
return 0;
}
F.牛牛的考试(dfs+贪心)
PS:真该死啊!!!!!!
首先考虑对于i点的实现情况:
对于i点所需的时间为
其中ans为所需时间,sum为子树和。
#include
#define ll long long
#define ls p<<1
#define rs p<<1|1
#define Ma 1000005
#define mod 1000000007
#define PLL pair
#define PDD pair
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define N 61
#define pb push_back
#define ld long double
using namespace std;
ll n;
ll a[Ma];
ll ans[Ma],sum[Ma];
ll f[Ma],ne[Ma],tot=0;
ll ma=0;
struct node{
ll b,e;
}t[Ma];
void add(ll x)
{
ne[++tot]=f[x];
f[x]=tot;
return;
}
void dfs(ll x)
{
for (ll i=f[x];i;i=ne[i])
{
dfs(t[i].e);
sum[x]+=sum[t[i].e];
ans[x]=max(ans[x],ans[t[i].e]);
}
ans[x]=max(ans[x],(sum[x]+1)/2);
sum[x]+=a[x],ans[x]+=a[x];
return;
}
void sol()
{
scanf("%lld",&n);
for (ll i=1;i<=n;i++)
scanf("%lld",&a[i]);
for (ll i=1;i