1. 程式人生 > 其它 >SDUT 2022 Spring Team Contest——11(補題)

SDUT 2022 Spring Team Contest——11(補題)

 題目連結:

Dyson Box - Gym 103118D - Virtual Judge (vjudge.net)

概述:給定方塊的座標,T時間內輸出前T個方塊下對齊與右對齊之後的邊長

思路:

以下對齊為例:

ans表示邊長總數

用map儲存每個x座標的個數

對於第一個:ans+=4;

對於後面的方塊:ans+=2;(兩條邊重合,減去)

判斷mp[x-1]與mp[x+1]與mp[x]的大小關係

大於等於的話會出現如下情況(以中間方塊為例,左右各有兩邊重合所以需要執行兩次ans-=2)

 最後輸出每一次的ans即可

#include <iostream>
#include 
<map> #include <algorithm> using namespace std; #define int long long #define endl '\n' #define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); signed main () { _ int n; cin >> n; int ans1=0,ans2=0; map<int,int> mx,my; while (n -- ) {
int x,y; cin >> x >> y; if(!mx[x]) ans1+=4; else ans1+=2; if(!my[y]) ans2+=4; else ans2+=2; mx[x]++,my[y]++; if(mx[x-1]>=mx[x]) ans1-=2; if(mx[x+1]>=mx[x]) ans1
-=2; if(my[y+1]>=my[y]) ans2-=2; if(my[y-1]>=my[y]) ans2-=2; cout << ans1 << " " << ans2 << endl; } }

 題目連結:

Adventurer's Guild - Gym 103118H - Virtual Judge (vjudge.net)

題目概述:

給出怪物的數量n,人物血量H,人物的攻擊S;
接下來n行,每一行為每隻怪物的血量h,攻擊s,價值w;

每消滅一個怪物,消耗h的血量和s的攻擊,S如果為負數,需要用H去彌補S,如果H為負數則結束;
輸出可以獲得的最大價值;

思路:

二維費用揹包+判斷

#include <bits/stdc++.h>
using namespace std;
const int N=1e3+10;
#define int long long
int v1[N],v2[N],f[N][N],w[N];
int n,m,k;
signed main()
{
    cin>>n>>m>>k;
    for (int i=1;i<=n;i++) cin>>v1[i]>>v2[i]>>w[i];
    for (int i=1;i<=n;i++)
        for (int j=m;j>0;j--)//血量
            for (int l=k;l>=0;l--)//耐力
            {
                if (j>v1[i]&&l>=v2[i])
                f[j][l]=max(f[j][l],f[j-v1[i]][l-v2[i]]+w[i]);
                else if (j>v1[i]&&l+j-v1[i]-v2[i]>0)
                f[j][l]=max(f[j][l],f[l+j-v1[i]-v2[i]][0]+w[i]);
            }
    cout<<f[m][k];
    return 0;
}

 題目連結:

Matrix Problem - Gym 103118M - Virtual Judge (vjudge.net)

題目概述:

給定二維的矩陣 c,要求當 c 的某處為 1 時,矩陣 a 和 b 的對應位置均為 1 ,否則AB矩陣對應位置不能相同,且矩陣 a 和 b 中的 1 需要連通。

思路:

構造題:

AB矩陣是互相對應的,對應關係是:C矩陣為1的時候AB一定為1 & 否則A矩陣為1B矩陣為0 | A矩陣為0B矩陣為1

如此只要知道A矩陣的值就能推出B矩陣相應的值

對於A矩陣的初始構造可以採用如下方法:(5*5為例)

 左側全部為1右側全部為0  (B矩陣相應的是左側全部為0右側全部為0)

左側的1彷彿是橋一樣能夠聯通所有的1(題目保證C矩陣最外圍一定不會有1)

那麼C矩陣的1就會是下面的兩種情況

(1):在A矩陣為1的地方出現

(2):在A矩陣為0的地方出現

對於(1)A矩陣無需變換

對於(2):

假設圖變成這樣

 在0那一行的1可以通過上邊或下面走到“橋”上實現聯通(也就是為什麼中間要一行0一行1)

結束

#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
const int N = 510;
#define int long long
#define endl '\n'
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

char a[N][N],b[N][N],c[N][N];

signed main ()
{
    _
    int n,m;
    cin >> n >> m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            a[i][j]=b[i][j]='0';//AB矩陣初始化
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin >> c[i][j];
    for(int i=1;i<=n;i++)
    {
        char k='1';
        if(i%2==0)k='0';  //A矩陣中間的地方按行奇偶性分為0和1
        for(int j=1;j<=m;j++)
            a[i][j]=k;
    }
    for(int i=1;i<=n;i++)a[i][1]='1',a[i][m]='0';  //初始化左側和右側
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(c[i][j]=='1')
                a[i][j]='1'; //改變C矩陣是1且A矩陣為0的地方
        }
    }
    for(int i=1;i<=n;i++)  //對於AC矩陣寫出B矩陣的值
    {
        for(int j=1;j<=m;j++)
        {
            if(c[i][j]=='1')
                b[i][j]='1';
            else
            {
                if(a[i][j]=='1')
                    b[i][j]='0';
                else
                    b[i][j]='1';
            }
        }
    }
    for(int i=1;i<=n;i++)   //輸出A矩陣
    {
        for(int j=1;j<=m;j++)
            cout << a[i][j];
        cout << endl;
    }
    for(int i=1;i<=n;i++)  //輸出B矩陣
    {
        for(int j=1;j<=m;j++)
            cout << b[i][j];
        cout << endl;
    }
}