思维题
Conveyor
难度:2/10
题解
首先,我们要知道,史莱姆不会同时走到同一个格子。
证明:设第
同时,我们也可以知道,第
std
:::info[代码]
#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,x,y,t,dp[125][125];
signed main(){
cin>>T;
while(T--){
memset(dp,0,sizeof(dp));
cin>>t>>x>>y;
if(t<x+y){
puts("NO");
continue;
}
dp[0][0]=t-x-y;
for(int i=0;i<=x;i++){
for(int j=0;j<=y;j++){
dp[i][j+1]+=(dp[i][j]+1)/2;
dp[i+1][j]+=dp[i][j]/2;
}
}
int nx=0,ny=0;
for(int i=1;i<=x+y;i++){
if(dp[nx][ny]&1)nx++;
else ny++;
}
if(nx==x&&ny==y)puts("YES");
else puts("NO");
}
return 0;
}
:::
[AGC027D] Modulo Matrix
难度:4/10
题解
因为,“对于任意两个相邻的数字,
其中
该方程的一组解是:
我们可以用这个柿子推出所有
那剩下的
因为题目要求所有的数不同,这里的
不对,这样赋值,
那怎么办呢?
既然一个质数不行,我们就用两个质数相乘,这样
std
:::info[代码]
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MX=30000;
int book[MX+5],prime[MX+5],pnum,a[1005],ans[505][505];
int gcd(int x,int y){
if(y==0)return x;
if(x==0)return y;
return gcd(y,x%y);
}
int lcm(int x,int y){
if(!x && !y)return 1;
if(!x)return y;
if(!y)return x;
return x/gcd(x,y)*y;
}
signed main(){
int n;
cin>>n;
for(int i=2;i<=MX;i++){
if(!book[i]){
prime[++pnum]=i;
}
for(int j=1;j<=pnum&&i*prime[j]<=MX;j++){
book[i*prime[j]]=1;
if(i%prime[j]==0){
break;
}
}
}
int ccc=1;
for(int i=1;i<=n*2;i+=2){
a[i]=prime[++ccc];
}
for(int i=n*2;i>=1;i-=2){
a[i]=prime[++ccc];
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(((i+j)&1)==0){
ans[i][j]=a[(i+j)/2]*a[(i-j)/2+n/2+n-1];
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(!ans[i][j]){
ans[i][j]=lcm(lcm(ans[i-1][j],ans[i][j-1]),lcm(ans[i+1][j],ans[i][j+1]))+1;
}
printf("%lld ",ans[i][j]);
}
puts("");
}
return 0;
}
:::
Subset with Zero Sum
难度:7/10
题解
首先,我们已知一个条件
化简得:
记
因为
所以
即
因为
我们就可以构造边
如何证明其一定可以在题目条件下找到解呢?
首先,题目保证数据有解。我们按照上述方法构造的图中每个点出度都为
std
:::info[代码]
#include<bits/stdc++.h>
using namespace std;
int T,n,a[1000005],rin[1000005];
vector<int>ed[1000005];
void addedge(int x,int y){
ed[x].push_back(y);
rin[y]++;
}
queue<int> q;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>T;
while(T--){
for(int i=1;i<=n;i++){
ed[i].clear();rin[i]=0;
}
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
addedge(i,i-a[i]);
}int num=n;
for(int i=1;i<=n;i++){
if(rin[i]==0)q.push(i);
}
while(!q.empty()){
int u=q.front();q.pop();num--;
for(int i=0;i<ed[u].size();i++){
int v=ed[u][i];
rin[v]--;
if(!rin[v])q.push(v);
}
}
printf("%d\n",num);
for(int i=1;i<=n;i++){
if(rin[i])printf("%d ",i);
}puts("");
}
return 0;
}
:::
[AGC002E] Candy Piles
难度:5/10
题解
构造题。
这一道题不分糖果堆的顺序,所以我们首先考虑排序。因为拿走一堆糖果绝对是拿得多更优,所以我们将糖果堆从大到小排。
然后这一道题就变成了这样一个问题:有
我们发现从上面拿好像不太好处理,所以我们就将其改为从下面拿。
这样就变成了一个网格图,我们每一次可以向右走一格或向上走一格,走出边界的人输。
显然只有当一个人走到右边是边界且上面是边界的格子时,他才会赢,我们称这样的点为“必胜格”。
然后我们就可以递推:两边都是必胜格,则该格子为必败格,否则该格子为必胜格。
我们打出表,发现一个规律:若一个格子为必胜格,则其左下方格子也为必胜格。我们根据这个性质,
std
:::info[代码]
#include<bits/stdc++.h>
using namespace std;
int n,a[100005];
bool pd(int x){
for(int i=1;i<=n;i++){
if(a[x+i]<x){
return (i&1)==0;
}
}
}
bool cmp(int x,int y){
return x>y;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
sort(a+1,a+1+n,cmp);
int x;
for(x=1;x<=n;x++)
if(x>a[x])break;
x--;
if(((a[x]-x)&1) || pd(x))puts("First");
else puts("Second");
return 0;
}
:::
CF830D Singer House
难度:6/10
题解
CF 神秘计数题。
注意到,数据范围 点开题解转变思路,设
std
:::info[代码]
/* Use the slash-star style comments or the system won't see your
identification information */
/*
ID: zhuheng1
TASK:
LANG: C++
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=100005;
//Debug Part
#undef _GLIBCXX_DEBUG
template <typename A, typename B>string to_string(pair<A, B> p);
template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res;}
template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; }
template <typename A> string to_string(A v) {bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res;}
template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; }
template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
//Debug Part End
ll dp[405][405];
int k;
void work(){
/*fill your code here*/
cin>>k;
dp[1][1]=1;
dp[1][0]=1;
for(int i=2;i<=k;i++){
for(int j=0;j<=k;j++){
for(int p=0;p<j;p++){
dp[i][j]+=dp[i-1][p]*dp[i-1][j-p-1]%mod;dp[i][j]%=mod;
}
//根独成一链
for(int p=0;p<=j;p++){
dp[i][j]+=dp[i-1][p]*dp[i-1][j-p]%mod*(j*2+1)%mod;dp[i][j]%=mod;
}
//根连上了一个
for(int p=0;p<=j+1;p++){
dp[i][j]+=dp[i-1][p]*dp[i-1][j+1-p]%mod*j%mod*(1+j)%mod;dp[i][j]%=mod;
}
//根连上了两个
}
}
cout<<dp[k][1];
return;
}
#ifdef int
signed main()
#else
int main()
#endif
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int T=1;
// cin>>T; /*If there's only one test case, comment this line.*/
while(T--){
work();
}
return 0;
}
/* Code written by
gala_xk (MarchWind)*/
:::