This commit is contained in:
e2hang
2025-08-14 12:59:59 +08:00
parent 8bfe9f31f3
commit 5ebd540fa5
4 changed files with 115 additions and 23 deletions

25
Luogu/P1007 独木桥.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include <iostream>
#include <vector>
using namespace std;
int main(){
int length, n;
int tmp;
int js;
vector<int> ma, mi;
cin >> length >> n;
for(int i = 0;i < n; i++){
cin >> tmp;
js = max(length - tmp + 1, tmp);
ma.push_back(js);
js = min(length - tmp + 1, tmp);
mi.push_back(js);
}
int smax = 0;
int smax2 = 0;
for(int i = 0;i < n; i++){
if(ma.at(i) > smax) smax = ma[i];
if(mi[i] > smax2) smax2 = mi[i];
}
cout << smax2 << " " << smax;
return 0;
}

View File

@@ -0,0 +1,19 @@
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> feb;
int n, a, m, x;
cin >> a >> n >> m >> x;
feb.reserve(n);
feb.push_back(1);feb.push_back(1);
for(int i = 2; i < n; i++){
feb[i] = feb[i - 1] + feb[i - 2];
}
int b = (m - (feb[n - 4] + 1) * a) / (feb[n - 3] - 1);
int out = (feb[x - 3] + 1) * a + (feb[x - 2] - 1) * b;
cout << out << endl;
return 0;
}
//5 7 32 4

View File

@@ -1,31 +1,27 @@
#include <cstring>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main(){
char a[21][11];
char sum[220]="";
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
struct cmp{
bool operator()(const string& a, const string& b){
return a + b > b + a;
}
int js=1;
char tmp[11]="";
while(js!=0){
js=0;
for(int i=0;i<n-1;i++){
if(strcmp(a[i],a[i+1])<0){
strcpy(tmp,a[i+1]);
strcpy(a[i+1],a[i]);
strcpy(a[i],tmp);
js++;
};
int main(){
set<string, cmp> a;
int n;
cin >> n;
string tmp;
for(int i = 0;i < n; i++){
cin >> tmp;
a.emplace(tmp);
}
for(string x : a){
cout << x ;
}
}
for(int i=0;i<n;i++){
strcat(sum,a[i]);
}
cout<<sum<<endl;
cout << endl;
return 0;
}

View File

@@ -0,0 +1,52 @@
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int charToInt(char c) {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'A' && c <= 'Z') return c - 'A' + 10;
if (c >= 'a' && c <= 'z') return c - 'a' + 10;
return 0;
}
char intToChar(int x) {
if (x < 10) return '0' + x;
return 'A' + (x - 10);
}
string add(const string& a, int jz) {
string b(a);
reverse(b.begin(), b.end());
string tmp(a.size() + 1, '0');
int carry = 0;
for (size_t i = 0; i < a.size(); i++) {
int ia = charToInt(a[i]);
int ib = charToInt(b[i]);
int sum = ia + ib + carry;
carry = sum / jz;
tmp[i] = intToChar(sum % jz);
}
if (carry > 0) tmp[a.size()] = intToChar(carry);
else tmp.pop_back();
return tmp;
}
bool check(const string& x) {
return equal(x.begin(), x.begin() + x.size()/2, x.rbegin());
}
int main(){
int jz;
string n;
cin >> jz >> n;
for (int i = 0; i <= 30; i++) {
if (check(n)) {
cout << "STEP=" << i << endl;
return 0;
}
n = add(n, jz);
}
cout << "Impossible!" << endl;
}