Mine Sweeper(构造)
题目传送门
思路
官方题解给的清清楚楚明明白白
AC Code
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
// #define TDS_ACM_LOCAL
const int N=2e5 +9;
int n;
void solve(){
cin>>n;
if(n<24){
cout<<"1 "<<n+1<<endl;
for(int i=1; i<=n+1; i++){
if(i&1) cout<<".";
else cout<<'X';
}
cout<<endl;
}
else{
cout<<"25 25"<<endl;
int t1=n/8, t2=0;
while(1){
if((n-t1*8)%3==0) {t2=(n-t1*8)/3; break;}
t1--;
}
for(int i=1; i<25; i++){
if(i&1) for(int j=1; j<=25; j++) cout<<".";
else{
for(int j=1; j<=25; j++){
if(!(j&1) && t1>0) cout<<"X", t1--;
else cout<<".";
}
}
cout<<endl;
}
for(int k=1; k<=25-t2; k++) cout<<".";
for(int k=25-t2+1; k<=25; k++) cout<<"X";
cout<<endl;
}
return ;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#ifdef TDS_ACM_LOCAL
freopen("D:\\VS code\\.vscode\\testall\\in.txt", "r", stdin);
freopen("D:\\VS code\\.vscode\\testall\\out.txt", "w", stdout);
#endif
int T;
cin>>T;
while(T--) solve();
return 0;
}
Permutation Counting
题目传送门
题目大意
对于一个字符串a,可以形成一个字符串b,方法为
b i = { 1 a i > a i + 1 0 a i < a i + 1 b_i=\{_{1\ \ \ \ a_i>a{i+1}}^{0\ \ \ \ a_i<a_{i+1}} bi={1 ai>ai+10 ai<ai+1
现在我们给您一个整数n和一个长度为n-1的序列b
求序列等于b的长度为n的排列数
思路
考虑
d
p
[
i
]
[
j
]
dp[i][j]
dp[i][j],其中
i
i
i表示当前的位置,
j
j
j为当前最后一位的数字的大小
在b中如果下一个为1,说明后面一个数比前一个数小,即为从1~j-1这些数作为末尾的情况转移过来。
记得前缀和优化一下
AC Code
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
// #define TDS_ACM_LOCAL
const int mod=1e9 +7;
const int N=5e3 +9;
int n, a[N], dp[N][N];
void solve(){
cin>>n;
memset(dp,0,sizeof(dp));
dp[1][1]=1;
for(int i=1; i<n; i++) cin>>a[i];
int sum=0;
for(int i=2; i<=n; i++){
sum=0;
if(a[i-1]){
for(int j=i-1; j; j--)
sum=(sum+dp[i-1][j])%mod, dp[i][j]=(dp[i][j]+sum)%mod;
}
else{
for(int j=2; j<=i; j++)
sum=(sum+dp[i-1][j-1])%mod, dp[i][j]=(dp[i][j]+sum)%mod;
}
}
int ans=0;
for(int i=1; i<=n; i++) ans=(ans+dp[n][i])%mod;
cout<<ans<<endl;
return ;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#ifdef TDS_ACM_LOCAL
freopen("D:\\VS code\\.vscode\\testall\\in.txt", "r", stdin);
freopen("D:\\VS code\\.vscode\\testall\\out.txt", "w", stdout);
#endif
int T;
cin>>T;
while(T--) solve();
return 0;
}
Task Scheduler
题目传送门
思路
参考大佬的思路吧:大佬
AC Code
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
// #define TDS_ACM_LOCAL
const int N=1e4 +9;
int n, m, k;
struct node{
int v, idx;
bool operator< (const node& a)const {
if(v!=a.v) return v>a.v;
return idx<a.idx;
}
}a[N];
void solve(){
cin>>n>>m>>k;
for(int i=1; i<=n; i++){
cin>>a[i].v;
a[i].idx=i;
}
if(k!=0) sort(a+1,a+1+n);
for(int i=1; i<n; i++) cout<<a[i].idx<<" ";
cout<<a[n].idx<<endl;
return ;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#ifdef TDS_ACM_LOCAL
freopen("D:\\VS code\\.vscode\\testall\\in.txt", "r", stdin);
freopen("D:\\VS code\\.vscode\\testall\\out.txt", "w", stdout);
#endif
int T;
cin>>T;
while(T--) solve();
return 0;
}