-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b37c842
commit dab9462
Showing
3 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <algorithm> | ||
#include <unordered_set> | ||
|
||
using namespace std; | ||
|
||
string N; int K; | ||
unordered_set<int> Visited[11]; | ||
|
||
int DFS(string Num = N, int Depth = 0) | ||
{ | ||
if(Visited[Depth].find(stoi(Num)) != Visited[Depth].end()) | ||
{ | ||
return -1; | ||
} | ||
else if(Depth == K) | ||
{ | ||
return stoi(Num); | ||
} | ||
else | ||
{ | ||
Visited[Depth].emplace(stoi(Num)); | ||
|
||
int MaxNum = -1; | ||
for(int i = 0; i < N.size() - 1; ++i) | ||
{ | ||
for(int j = i + 1; j < N.size(); ++j) | ||
{ | ||
if(i == 0 && Num[j] == '0') | ||
{ | ||
continue; | ||
} | ||
|
||
string TmpNum = Num; | ||
swap(TmpNum[i], TmpNum[j]); | ||
|
||
MaxNum = max(MaxNum, DFS(TmpNum, Depth + 1)); | ||
} | ||
} | ||
|
||
return MaxNum; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
cin.tie(nullptr)->sync_with_stdio(false); | ||
|
||
cin >> N >> K; | ||
|
||
cout << DFS(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using namespace std; | ||
using Loc = pair<int, int>; | ||
|
||
#define x first | ||
#define y second | ||
|
||
Loc operator+(const Loc &a, const Loc &b) { return {a.x + b.x, a.y + b.y}; } | ||
|
||
struct BC { | ||
int Index, X, Y, C, P; | ||
|
||
BC() : Index(-1), X(-1), Y(-1), C(-1), P(-1) {} | ||
BC(int inIndex, int inX, int inY, int inC, int inP) | ||
: Index(inIndex), X(inX), Y(inY), C(inC), P(inP) {} | ||
|
||
[[nodiscard]] inline int D(const Loc &loc) const { | ||
return abs(X - loc.x) + abs(Y - loc.y); | ||
} | ||
}; | ||
|
||
int main() { | ||
cin.tie(nullptr)->sync_with_stdio(false); | ||
const vector<Loc> offset = {{}, {-1, 0}, {0, 1}, {1, 0}, {0, -1}}; | ||
|
||
int M, A; | ||
vector<int> aMvTrajectories, bMvTrajectories; | ||
vector<BC> BCs; | ||
Loc aLoc, bLoc; | ||
|
||
auto Input = [&]() { | ||
cin >> M >> A; | ||
aMvTrajectories.assign(M + 1, 0); | ||
bMvTrajectories.assign(M + 1, 0); | ||
BCs.assign(A, {}); | ||
|
||
for (int T = 1; T <= M; ++T) { | ||
cin >> aMvTrajectories[T]; | ||
} | ||
for (int T = 1; T <= M; ++T) { | ||
cin >> bMvTrajectories[T]; | ||
} | ||
|
||
int bcCnt = 0; | ||
for (auto &[Index, X, Y, C, P] : BCs) { | ||
cin >> Y >> X >> C >> P; | ||
Index = bcCnt++; | ||
} | ||
|
||
aLoc = {1, 1}; | ||
bLoc = {10, 10}; | ||
}; | ||
|
||
auto Charge = [&]() { | ||
int maxCharge = 0; | ||
for (const auto &aBC : BCs) { | ||
const int aDist = aBC.D(aLoc); | ||
const int aAmt = aDist <= aBC.C ? aBC.P : 0; | ||
|
||
for (const auto &bBC : BCs) { | ||
const int bDist = bBC.D(bLoc); | ||
const int bAmt = bDist <= bBC.C ? bBC.P : 0; | ||
|
||
const int curCharge = | ||
(aBC.Index != bBC.Index ? aAmt + bAmt : max(aAmt, bAmt)); | ||
|
||
maxCharge = max(maxCharge, curCharge); | ||
} | ||
} | ||
return maxCharge; | ||
}; | ||
|
||
auto Move = [&]() { | ||
int totalCharge = 0; | ||
for (int time = 0; time <= M; ++time) { | ||
aLoc = aLoc + offset[aMvTrajectories[time]]; | ||
bLoc = bLoc + offset[bMvTrajectories[time]]; | ||
|
||
totalCharge += Charge(); | ||
} | ||
return totalCharge; | ||
}; | ||
|
||
int T; | ||
cin >> T; | ||
for (int tc = 1; tc <= T; ++tc) { | ||
Input(); | ||
cout << "#" << tc << " " << Move() << "\n"; | ||
} | ||
|
||
return 0; | ||
} |