1. 程式人生 > 其它 >2021.7.27--Benelux Algorithm Programming Contest 2020 補提

2021.7.27--Benelux Algorithm Programming Contest 2020 補提

I Jigsaw

題目內容:

連結:https://ac.nowcoder.com/acm/contest/18454/I
來源:牛客網

You have found an old jigsaw puzzle in the attic of your house, left behind by the previous occupants. Because you like puzzles, you decide to put this one together. But before you start, you want to know whether this puzzle was left behind for
a reason. Maybe it is incomplete? Maybe the box contains pieces from multiple puzzles? If it looks like a complete puzzle, you also need to know how big your work surface needs to be. Nothing worse than having to start a jigsaw over because you started on a small table. The box does not tell you the dimensions w × h of the puzzle, but you can quickly count the three types of pieces
in the box: • Corner pieces, which touch two of the edges of the puzzle. • Edge pieces, which touch one of the edges of the puzzle. • Center pieces, which touch none of the edges of the puzzle. Do these pieces add up to a complete jigsaw puzzle? If so, what was the original size of the jigsaw puzzle? 輸入描述: The input consists of: • One line containing three integers c, e, and m (
0 ≤ c,e,m ≤ 10 9 ), the number of corner pieces, edge pieces, and center pieces respectively. 輸出描述: If there exist numbers w and h satisfying w ≥ h ≥ 2 such that the original size of the jigsaw puzzle could have been w×h, then output a single line containing w and h. Otherwise, output “impossible”. If there are multiple valid solutions, you may output any one of them. 示例1 輸入 複製 4 8 4 輸出 複製 4 4 示例2 輸入 複製 4 10 14 輸出 複製 impossible 示例3 輸入 複製 4 12 6 輸出 複製 impossible 示例4 輸入 複製 4 2048 195063 輸出 複製 773 255
View Code

題意:有一組拼圖,分別給出角塊c、邊緣塊e、中心塊m的數量,問能否構成一個完整的拼圖。若能則輸出該拼圖的w和h(w>=h>=2),不能則輸出“impossible”

思路:題目中w和h>=2,所以角塊數至少為4,還可以根據拼圖經驗可得出方程:w*h==c+e+m; (w-2+h-2)*2==e; (w-2)*(h-2)==m;

所以可據此得到程式碼:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int c,e,m;
    cin>>c>>e>>m;
    if(c>=4){
        if(e==0&&m==0){
            cout<<2<<" "<<2<<endl;
            return 0;
        }
        else if(e!=0&&m==0&&e%2==0)
        {
            cout<<e/2+2<<" "<<2<<endl;
            return 0;
        }
        else{
            int w,h;
            int t=c+e+m;
            for(w=2;w*w<=c+e+m;w++)
            {
                if(t%w==0)
                {
                    h=t/w;
                    if((w-2+h-2)*2==e&&(w-2)*(h-2)==m)
                    {
                        if(w<h)swap(w,h);
                        cout<<w<<" "<<h<<endl;
                        return 0;
                    }
                }
            }
        }
        
    }
    cout<<"impossible"<<endl;
}
View Code

C Corrupted Contest

題目內容:

連結:https://ac.nowcoder.com/acm/contest/18454/C
來源:牛客網

You are organizing a programming competition in which the rank of a team is fifirst determined by how many problems they have solved. In case of a tie, the team with the lowest time penalty is ranked above the other. However, contrary to the BAPC, the time penalty is equal to t if the latest accepted submission was submitted in the tth minute, or 0 if no problem was solved.
For example, if team A solved their fifirst problem in the 5th minute, their second problem in the 10th minute and their third problem in the 60th minute, then their time penalty is 60. If team B also solved three problems, in the 30th, 40th and 50th minute, their time penalty is 50 and they would rank above team A.
 The contest has fifinished and you would like to enter the fifinal standings. However, due to a corrupted fifile you have lost part of the scoreboard. In particular, the column indicating how many problems each team has solved is gone. You do still have the time penalties of all the teams and know that they are in the right order. You also remember how many problems the contest had. You wonder whether, given this information, it is possible to uniquely reconstruct the number of problems that each team has solved.

輸入描述:

The input consists of:
     •One line containing two integers: n (1 ≤ n ≤ 104), the number of teams participating,and p (1 ≤ p ≤ 104), the number of contest problems.
     •n lines with on line i the time score tiin minutes (0 ≤ ti ≤ 106) of the team that is ranked in the ith place.
A positive time score of t indicates that a team has submitted their last accepted submission in the tth minute. A time score of 0 indicates that a team hasn’t solved any problem.
The input always originates from a valid scoreboard.

輸出描述:

If it is possible to uniquely reconstruct the scores of all the teams, output n lines containing the number of problems that the ith team has solved on the ith line. Otherwise, output “ambiguous”.

示例1
輸入
複製

9 3
140
75
101
120
30
70
200
0
0

輸出
複製

3
2
2
2
1
1
1
0
0

示例2
輸入
複製

6 3
100
40
40
50
0
0

輸出
複製

ambiguous
View Code

題意:你正在組織一場程式設計比賽,其中一個團隊的排名首先取決於他們解決了多少問題。

平局的情況下,罰時最少的球隊排在另一隊之上。但是,與 BAPC 相反,如果最新接受的提交是在第 t 分鐘提交的,則時間懲罰等於 t,如果沒有解決問題,則時間懲罰等於 0。

比賽已結束,您想進入決賽排名。但是,由於檔案損壞,您丟失了記分板的一部分。特別是,顯示每個團隊解決了多少問題的列不見了。你仍然有所有球隊的時間處罰,並且知道他們的順序是正確的。你還記得比賽有多少問題。您想知道,根據這些資訊,是否可以唯一地重建每個團隊已解決的問題數量。

輸入描述: 一行包含兩個整數:n (1 ≤ n ≤ 104),參賽隊數,p (1 ≤ p ≤ 104),比賽題數。 • n 行,第i 行是排在第i 位的球隊的時間得分tiin 分鐘(0 ≤ ti ≤ 106)。 t 的正時間分數表示團隊在第 t 分鐘提交了他們最後一次接受的提交。時間分數為 0 表示團隊沒有解決任何問題。 輸入始終來自有效的記分板。

輸出描述: 如果可以唯一地重建所有團隊的分數,則輸出 n 行,其中包含第 i 行上第 i 個團隊已解決的問題數。否則,輸出“ambiguous”。

思路: 可以確定分數時: 1.從榜首到最後一名均為0 2. 不為0時,過題數從m到1或從m到0

不可以確定分數時: 1. 最後一名罰時為0但過題數不為0 2.最後一名罰時為0,但過題數不為1

程式碼:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,p;
    cin>>n>>p;
    int s[10010],v[10010],k=0;
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        if(s[i]!=0)k=1;
    }
    if(k==0)
    {
        while(n--){
            cout<<0<<endl;
        }
       
    }
    else{
        v[0]=p;
        for(int i=1;i<n;i++)
        {
            if(s[i]<s[i-1])v[i]=--p;
            else v[i]=p;
        }
        if((v[n-1]!=1&&s[n-1]!=0)||(v[n-1]!=0&&s[n-1]==0))//此處不要弄錯
            cout<<"ambiguous"<<endl;
        else {
            for(int i=0;i<n;i++)cout<<v[i]<<endl;
        }
    }
}
            
View Code