组队训练记录(4):2020ICPC南京

2022.9.27
在这里插入图片描述
在这里插入图片描述
7题中等罚时。。。怎么进rk前十了。

感觉20年的场都很友好 ,vp20上海的时候也是金牌区,但是这21的场不知道怎么都不是很行。
但是这场真的很痛苦 ,两个打表题。

A.Ah, It’s Yesterday Once More

构造题,思路是找到一个尽可能长的路径打表输出即可。

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

const int N = 1e6 + 10;

string ans[21]={
    "",
    "11101110111011111011",
    "10101010101100101101",
    "10101010110110110111",
    "10101011011011011001",
    "10101101101101101101",
    "10110100110110110110",
    "11010111011011011011",
    "01010001101101101101",
    "11011110110110110111",
    "10100011011011011001",
    "11111101101101101100",
    "00000110110110110111",
    "11111011011011011001",
    "10001101101101101111",
    "11110110110110100001",
    "00011011011010111101",
    "11101101101010000110",
    "10110110101010111011",
    "11011010101010101001",
    "01101110111011101111",
};
inline void solve(){
    cout<<"20 20\n";
    for(int i=1;i<=20;i++){
        cout<<ans[i]<<endl;;
    }
}

signed main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    int t = 1; // cin >> t;
    while(t--) solve();
    return 0;
}

E. Evil Coordinate

四个方向可以选择先全走一个方向再走另一个方向,然后全排列枚举即可。

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

const int N = 1e6 + 10;

int x,y;
string s,ans;
int tot[15];
char mp[]="UDLR";
bool ck2(){
    int stx=0,sty=0;
    for(int i=0;i<ans.size();i++){
        if(ans[i]=='U'){
            sty++;
        }
        else if(ans[i]=='D'){
            sty--;
        }
        else if(ans[i]=='R'){
            stx++;
        }
        else {
            stx--;
        }
        if(stx==x&&sty==y){
            return false;
        }
    }
    return true;
}
int g[10];
bool ck(){
    memset(tot,0,sizeof tot);
    for(int i=0;i<s.size();i++){
        if(s[i]=='U'){
            tot[0]++;
        }
        else if(s[i]=='D'){
            tot[1]++;
        }
        else if(s[i]=='L'){
            tot[2]++;
        }
        else if(s[i]=='R'){
            tot[3]++;
        }
    }
    g[0]=0,g[1]=1,g[2]=2,g[3]=3;
    do{
        int fg=1;
        ans="";
        for(int i=0;i<4;i++){
            for(int j=0;j<tot[g[i]];j++){
                ans+=mp[g[i]];
            }
        }
        if(ck2()){
            cout<<ans<<endl;
            return true;
        }
    }while(next_permutation(g,g+4));
    return false;
}
inline void solve(){
    cin>>x>>y>>s;
    memset(tot,0,sizeof tot);
    for(int i=0;i<s.size();i++){
        if(s[i]=='U'){
            tot[0]++;
        }
        else if(s[i]=='D'){
            tot[1]++;
        }
        else if(s[i]=='L'){
            tot[2]++;
        }
        else if(s[i]=='R'){
            tot[3]++;
        }
    }
    if(x==0&&y==0||!ck()){
        cout<<"Impossible\n";
        return;
    }
}

signed main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    int t = 1; cin >> t;
    while(t--) solve();
    return 0;
}

F.Fireworks

整数三分即可。

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

const int N = 1e6 + 10;
int n,m,p;
double qpow(double x,int y,double res=1){
    for(;y;x*=x,y>>=1) if(y&1) res*=x;
    return res;
}
double ck(int n,int m,int k,double p){
    return (k*n+m)/(1-qpow(p,k));
}
inline void solve(){
    cin>>n>>m>>p;
    double ans=1e18,shibai=(10000-p)/10000.,fenmu=shibai;
    int l=1,r=1e7;
    while(l+10<r){
        int lmid=l+(r-l)/3,rmid=r-(r-l)/3;
        double lans=ck(n,m,lmid,shibai),rans=ck(n,m,rmid,shibai);
        if(lans>rans){
            l=lmid;
        }
        else{
            r=rmid;
        }
    }
    for(int i=l;i<=r;i++){
        ans=min(ans,ck(n,m,i,shibai));
    }
    cout<<ans<<endl;
}
signed main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout<<fixed<<setprecision(12);
    int t = 1;  cin >> t;
    while(t--) solve();
    return 0;
}

H. Harmonious Rectangle

弱智打表题。
根据鸽巢定理知道行列最多为7,然后把所有7*7以内的答案打表打出来计算即可。
vp的时候打了2h的表,没啥意思。

#include <bits/stdc++.h>
#define int long long 
#define Pa pair<int,int> 
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define endl '\n'
using namespace std;    

const int N=2e5+5;
const int mod = 1e9+7;
int a[][10]={
    {},
    {},
    {},
    {0,0,390,3198},
    {0,0,1800,13176,24336},
    {0,0,6120,27000,4320,4320},
    {0,0,13680,13680},
    {0,0,15120,15120},
};
int qpow(int x,int y,int res=1){
    for(;y;y>>=1,(x*=x)%=mod) if(y&1)(res*=x)%=mod;
    return res;
}
void solve()
{
    int x,y;cin>>x>>y;
    if(x>y)swap(x,y);
    if(x==1){
        cout<<0<<endl;
    }
    else if(x==2&&y==2){
        cout<<15<<endl;
    }
    else if(y>=8){
        cout<<qpow(3,x*y)<<endl;
    }
    else{
        cout<<(qpow(3,x*y)-a[y][x]+mod)%mod<<endl;
    }
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<fixed<<setprecision(12);
    int T=1;
    cin>>T;
    while(T--) solve();
}

K. K Co-prime Permutation

签到题,,旋转前k个即可。

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

const int N = 1e6 + 10;

inline void solve(){
    int n, k; cin >> n >> k;
    if(!k) cout << -1 << endl;
    else{
        cout << k;
        for(int i = 1; i < k; i++) cout << ' ' << i;
        for(int i = k + 1; i <= n; i++) cout << ' ' << i;
        cout << endl;
    }
}

signed main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    int t = 1; // cin >> t;
    while(t--) solve();
    return 0;
}

L. Let’s Play Curling

队友写的不知道啥题。

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

const int N = 1e6 + 10;
int a[N], b[N];
inline void solve(){
    int n,m; cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=m;i++) cin>>b[i];
    sort(a+1,a+1+n);
    sort(b+1,b+1+m);
    int ans=0;
    int r=upper_bound(a+1,a+1+n,b[m])-a;
    int l=lower_bound(a+1,a+1+n,b[1])-a-1;
    ans=max({ans,n-r+1,l});
    for(int i=2;i<=m;i++)
    {
        if(b[i]==b[i-1]) continue;
        int l=b[i-1], r=b[i];
        int pl=upper_bound(a+1,a+1+n,l)-a;
        int pr=lower_bound(a+1,a+1+n,r)-a; 
        pr--;
        // cout<<i<<' '<<pl<<' '<<pr<<"\n";
        ans=max(ans,pr-pl+1);
    }
    if(ans) cout<<ans<<"\n";
    else cout<<"Impossible\n";
}

signed main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    int t = 1;  cin >> t;
    while(t--) solve();
    return 0;
}

M. Monster Hunter

树背包模板题。

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

const int N = 1e6 + 10,inf =1e16;
int n,m;
vector<int>p[200005];
int dp1[2005][2005],dp2[2005][2005];
int sz[20005],w[200005];
void dfs(int u){
    sz[u]=1;
    dp1[u][1]=w[u];
    dp2[u][0]=0;
    for(auto v:p[u]){
        dfs(v);
       // dp1[u][0]+=dp1[v][0]+w[v];
        for(int i=sz[u]-1;i>=0;i--){
            for(int j=0;j<=sz[v];j++){
                dp2[u][i+j]=min(dp2[u][i+j],dp2[u][i]+min(dp1[v][j],dp2[v][j]));
            }
        }
        for(int i=sz[u];i>0;i--){
            for(int j=0;j<=sz[v];j++){
                dp1[u][i+j]=min(dp1[u][i+j],dp1[u][i]+min(dp2[v][j],dp1[v][j]+w[v]));
            }
        }
        sz[u]+=sz[v];
    }
}
inline void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        p[i].clear();
        for(int j=0;j<=n;j++){
            dp1[i][j]=dp2[i][j]=inf;
        }
    }
    for(int i=2;i<=n;i++){
        int f;cin>>f;
        p[f].push_back(i);
    }
    for(int i=1;i<=n;i++){
        cin>>w[i];
    }
    dfs(1);
    for(int i=n;~i;i--){
        cout<<min(dp1[1][i],dp2[1][i])<<" \n"[i==0];
    }
}
signed main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout<<fixed<<setprecision(12);
    int t = 1;  cin >> t;
    while(t--) solve();
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值