#题1
能放就放的思想
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
string ori,temp=".";
cin >> n;
cin >> ori;
for (int i = 0; i < n; i++) {
if (ori[i] == '.'&&temp!="L") {
if (ori[i + 1] == '.'||i+1==n) {
ori[i] = 'C';
}
}
temp = ori[i];
}
cout << ori;
}
#题2
a1[i] - ‘A’) >= 0,考试的时候没打等于,而样例有没有0,我直接完美的跳进了自己挖到坑,之后越找越急,在往后就全崩了。
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
int a[maxn], b[maxn];
int main() {
//freopen("3in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
string a1, b1;
map <int, string> shu;
shu[0] = "0";
shu[1] = "1";
shu[2] = "2";
shu[3] = "3";
shu[4] = "4";
shu[5] = "5";
shu[6] = "6";
shu[7] = "7";
shu[8] = "8";
shu[9] = "9";
shu[10] = "A";
shu[11] = "B";
shu[12] = "C";
shu[13] = "D";
shu[14] = "E";
shu[15] = "F";
cin >> a1 >> b1;
if (a1.length() < b1.length()) {
swap(a1, b1);
}
reverse(a1.begin(), a1.end());
reverse(b1.begin(), b1.end());
for (int i = 0; i < a1.length(); i++) {
if ((a1[i] - 'A') >= 0) {
a[i] = a1[i] - 'A' + 10;
}
else {
a[i] = a1[i] - '0';
}
}
for (int i = 0; i < b1.length(); i++) {
if ((b1[i] - 'A') >= 0) {
b[i] = b1[i] - 'A' + 10;
}
else {
b[i] = b1[i] - '0';
}
}
int temp = 0;
int sum[2000]={0};
for (int i = 0; i < b1.length(); i++) {
for (int j = 0; j < a1.length(); j++) {
temp = b[i] * a[j] + sum[i + j];
while (temp > 15) {
temp -= 16;
sum[i + j + 1] = sum[i + 1 + j] + 1;
}
sum[i + j] = temp;
}
}
reverse(sum, sum + maxn);
int i = 0;
for (; i < maxn; i++) {
if (sum[i] == 0 && sum[i + 1] != 0) {
break;
}
}
i++;
string sum1,c;
for (; i < maxn; i++) {
c = shu[sum[i]];
sum1 = sum1 + c;
}
cout << sum1;
}
#题3
在本地调试的时候把scan函数里的m改成了100,后面教的时候没发现,之后,之后就寄了。。
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, m, ori[maxn];
bool scan(int k) {
int temp = 0;
for (int i = 0; i < n; i++) {
if (ori[i] - temp > m) {
temp += ori[i] - temp - m;
}
if (ori[i] - temp < 0) {
return false;
}
temp += k;
}
return true;
}
int main() {
//freopen("prob3in.txt", "r", stdin);
//freopen("prob3out.txt", "w", stdout);
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> ori[i];
}
sort(ori, ori + n);
int r, l;
r = m, l = 0;
while (l < r) {
int mid = (l + r) / 2 + 1;
if (scan(mid) == 1) {
l = mid;
}
else {
r = mid - 1;
}
}
cout << r;
}
#题4
测试样例有一种链表上的节点数小于n的情况,考试的时候没想到,。
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
map <string, int> ori;
map <int, string> next1;
map<int, string> address;
int num[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
string add0;
cin >> add0 >> n >> k;
for (int i = 0; i < n; i++) {
int temp2;
string temp1, temp3;
cin >> temp1 >> temp2 >> temp3;
ori[temp1] = temp2;
address[temp2] = temp1;
next1[temp2] = temp3;
}
string next2 = add0;
for (int i = 0; i < n; i++) {
num[i] = ori[next2];
if (next1[num[i]] == "-1") {
n = i + 1;
break;
}
next2 = next1[num[i]];
}
//读入
for (int i = 0; i < (n / k); i++) {
static int* p = num;
if ((i + 1) * k > n) {
break;
}
reverse(p, p + k);
p += k;
}
//翻转
for (int i = 0; i < n - 1; i++) {
cout << address[num[i]] << " " << num[i] << " " << address[num[i + 1]] << endl;
}
cout << address[num[n - 1]] << " " << num[n - 1] << " " << -1 << endl;
}
#题5
求导后分三段,多好的方法啊,可惜我没想到,我还想他给个一元二次的求根公式干嘛。
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
double a, b, c, d, p, q;
double a1, b1, c1;
double san(double x) {
return x * x * x * a + b * x * x + c * x + d;
}
double er(double x) {
return x * x * a1 + x * b1 + c1;
}
void suan(double l, double r) {
double mid = (l + r) / 2;
if (er(mid) > 0) {
while (r - l > 0.00000001)
{
mid = (r + l) / 2;
if (san(mid) > 0) {
r = mid;
}
else {
l = mid;
}
}
cout << r << " ";
}
else {
while (r - l > 0.00000001)
{
mid = (r + l) / 2;
if (san(mid) < 0) {
r = mid;
}
else {
l = mid;
}
}
cout << r << " ";
}
}
int main() {
//freopen("3in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int t;
cin >> t;
while (t--) {
cin >> a >> b >> c >> d >> p >> q;
a1 = 3 * a;
b1 = 2 * b;
c1 = c;
double m2 = (-b1 - sqrt(b1 * b1 - 4 * a1 * c1)) / (2 * a1);
double m3 = (-b1 + sqrt(b1 * b1 - 4 * a1 * c1)) / (2 * a1);
cout << fixed << setprecision(6);
if (m2 > m3)swap(m2, m3);
suan(p, m2);
suan(m2, m3);
suan(m3, q);
cout << endl;
}
}