'commit'
This commit is contained in:
47
GESP/Level4/GESP202306/4_1.cpp
Normal file
47
GESP/Level4/GESP202306/4_1.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
typedef long long LL;
|
||||
const int N = 110;
|
||||
int a[N], al;
|
||||
// 变换
|
||||
int change(int y) {
|
||||
y *= 7;
|
||||
while (y > 9)
|
||||
y = y / 10 + y % 10;
|
||||
return y;
|
||||
}
|
||||
|
||||
// 检查x是不是幸运数
|
||||
bool check(LL x) {
|
||||
int idx = 0;
|
||||
while (x) {
|
||||
idx++;
|
||||
int y = x % 10;
|
||||
x /= 10;
|
||||
if (idx % 2 == 1) // 奇数位
|
||||
y = change(y);
|
||||
// 偶数位不变
|
||||
a[++al] = y;
|
||||
}
|
||||
LL q = 0;
|
||||
|
||||
// 反着拼回来
|
||||
for (int i = al; i; i--)
|
||||
q = q * 10 + a[i];
|
||||
|
||||
return q % 8 == 0;
|
||||
}
|
||||
int main() {
|
||||
int N;
|
||||
cin >> N;
|
||||
while (N--) {
|
||||
al = 0;
|
||||
LL x;
|
||||
cin >> x;
|
||||
if (check(x))
|
||||
cout << "T" << endl;
|
||||
else
|
||||
cout << "F" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
104
GESP/Level4/GESP202306/4_2.cpp
Normal file
104
GESP/Level4/GESP202306/4_2.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 256;
|
||||
int b[N]; // 桶
|
||||
vector<int> top16;
|
||||
|
||||
// 十六进制转十进制
|
||||
int toDec(string s) {
|
||||
int sum = 0;
|
||||
if (s[0] >= 'A' && s[0] <= 'F')
|
||||
sum = (s[0] - 'A' + 10) * 16;
|
||||
else
|
||||
sum = (s[0] - '0') * 16;
|
||||
if (s[1] >= 'A' && s[1] <= 'F')
|
||||
sum += (s[1] - 'A' + 10);
|
||||
else
|
||||
sum += (s[1] - '0');
|
||||
return sum;
|
||||
}
|
||||
|
||||
// 十进制转十六进制
|
||||
string toHex(int x) {
|
||||
string res;
|
||||
while (x) {
|
||||
int t = x % 16;
|
||||
if (t >= 10)
|
||||
res += t - 10 + 'A';
|
||||
else
|
||||
res += t + '0';
|
||||
x /= 16;
|
||||
}
|
||||
reverse(res.begin(), res.end());
|
||||
if (res.empty())
|
||||
return "00";
|
||||
if (res.size() == 1)
|
||||
return "0" + res;
|
||||
return res;
|
||||
}
|
||||
|
||||
// 在重新排完序的数据中找出离q最近的灰阶索引号
|
||||
char find(int q) {
|
||||
int mi = INT_MAX, mp = 0;
|
||||
for (int i = 0; i < top16.size(); i++) {
|
||||
if (abs(q - top16[i]) < mi) {
|
||||
mi = abs(q - top16[i]);
|
||||
mp = i;
|
||||
}
|
||||
}
|
||||
if (mp >= 10)
|
||||
return (char)(mp - 10 + 'A');
|
||||
return (char)(mp + '0');
|
||||
}
|
||||
string c[N]; // 原始数组
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
string s;
|
||||
cin >> s; // 录入字符串
|
||||
c[i] = s; // 记录原始录入的数据
|
||||
for (int j = 0; j < s.size(); j += 2) {
|
||||
string x;
|
||||
x.push_back(s[j]);
|
||||
x.push_back(s[j + 1]);
|
||||
b[toDec(x)]++; // 记录桶
|
||||
}
|
||||
}
|
||||
|
||||
// 开始查找前16位数量多的数字,那我就直接找16次最大的数字是多少,找到后我就把它的数量修改为0
|
||||
for (int i = 1; i <= 16; i++) {
|
||||
int mx = 0, mp = 0;
|
||||
for (int j = 0; j < 256; j++)
|
||||
if (b[j] > mx) {
|
||||
mx = b[j];
|
||||
mp = j;
|
||||
}
|
||||
b[mp] = 0; // 清零
|
||||
// 前十六位的灰阶索引号
|
||||
top16.push_back(mp);
|
||||
}
|
||||
|
||||
// 输出前16位的灰阶索引号
|
||||
for (int i = 0; i < top16.size(); i++)
|
||||
cout << toHex(top16[i]);
|
||||
|
||||
cout << endl;
|
||||
|
||||
// 遍历原始数据
|
||||
for (int i = 1; i <= n; i++) {
|
||||
string s = c[i];
|
||||
// 两位一组
|
||||
for (int j = 0; j < s.size(); j += 2) {
|
||||
string x;
|
||||
x.push_back(s[j]);
|
||||
x.push_back(s[j + 1]);
|
||||
int q = toDec(x);
|
||||
// 这个数字,与res中哪个数字最接近,接近的含义是差的绝对值最小
|
||||
cout << find(q);
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
BIN
GESP/Level4/GESP202306/GESP C++四级认证试卷2023年6月.pdf
Normal file
BIN
GESP/Level4/GESP202306/GESP C++四级认证试卷2023年6月.pdf
Normal file
Binary file not shown.
102
GESP/Level4/GESP202306/Test.cpp
Normal file
102
GESP/Level4/GESP202306/Test.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 256;
|
||||
int b[N];
|
||||
string c[N]; // 原字符串数组
|
||||
vector<int> v;
|
||||
|
||||
int toDec(string s) { // s是一个两位的十六进制字符串
|
||||
int sum = 0;
|
||||
if (s[0] >= 'A' && s[0] <= 'F')
|
||||
sum = (s[0] - 'A' + 10) * 16;
|
||||
else
|
||||
sum = (s[0] - '0') * 16;
|
||||
|
||||
if (s[1] >= 'A' && s[1] <= 'F')
|
||||
sum += s[1] - 'A' + 10;
|
||||
else
|
||||
sum += s[1] - '0';
|
||||
return sum;
|
||||
}
|
||||
|
||||
// 十进制转十六进制
|
||||
string toHex(int x) {
|
||||
string res;
|
||||
while (x) {
|
||||
int t = x % 16;
|
||||
if (t >= 10)
|
||||
res += t - 10 + 'A';
|
||||
else
|
||||
res += t + '0';
|
||||
x /= 16;
|
||||
}
|
||||
reverse(res.begin(), res.end());
|
||||
return res;
|
||||
}
|
||||
char find(string s) {
|
||||
int x = toDec(s);
|
||||
int mi = INT_MAX, mp = 0;
|
||||
for (int i = 0; i < v.size(); i++) {
|
||||
if (abs(x - v[i]) < mi) {
|
||||
mi = abs(x - v[i]);
|
||||
mp = i;
|
||||
}
|
||||
}
|
||||
if (mp >= 10)
|
||||
return (char)(mp - 10 + 'A');
|
||||
return (char)(mp + '0');
|
||||
}
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
string s;
|
||||
cin >> s;
|
||||
c[i] = s; // 把原始数组记录下来,后面要用
|
||||
for (int j = 0; j < s.size(); j += 2) {
|
||||
char x = s[j], y = s[j + 1];
|
||||
string t;
|
||||
t.push_back(x);
|
||||
t.push_back(y);
|
||||
// 我要把两位字符串的十六进制数转为十进制
|
||||
b[toDec(t)]++;
|
||||
}
|
||||
}
|
||||
// 记录前十六名都有谁
|
||||
|
||||
// 我需要知道哪个灰阶颜色最多,前十六位都有谁?
|
||||
for (int i = 1; i <= 16; i++) {
|
||||
int mx = 0, mp = 0; // 每次都找最大值,并且记录最大值所在的pos位置
|
||||
for (int j = 0; j < 256; j++) {
|
||||
if (b[j] > mx) {
|
||||
mx = b[j];
|
||||
mp = j;
|
||||
}
|
||||
}
|
||||
// 因为老大找出了,就不需要下次再参与评比了,否则它会一直是老大
|
||||
b[mp] = 0;
|
||||
v.push_back(mp); // 把前十六名都记录下来
|
||||
}
|
||||
|
||||
for (int i = 0; i < v.size(); i++) {
|
||||
string s = toHex(v[i]);
|
||||
if (s.size() == 1)
|
||||
s = "0" + s;
|
||||
cout << s;
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
string s = c[i];
|
||||
for (int j = 0; j < s.size(); j += 2) {
|
||||
char x = s[j], y = s[j + 1];
|
||||
string t;
|
||||
t.push_back(x);
|
||||
t.push_back(y);
|
||||
cout << find(t);
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
26
GESP/Level4/GESP202306/Test2.cpp
Normal file
26
GESP/Level4/GESP202306/Test2.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
// 十进制转十六进制
|
||||
string toHex(int x) {
|
||||
string res;
|
||||
while (x) {
|
||||
int t = x % 16;
|
||||
if (t >= 10)
|
||||
res += t - 10 + 'A';
|
||||
else
|
||||
res += t + '0';
|
||||
x /= 16;
|
||||
}
|
||||
reverse(res.begin(), res.end());
|
||||
if (res.empty())
|
||||
return "00";
|
||||
if (res.size() == 1)
|
||||
return "0" + res;
|
||||
return res;
|
||||
}
|
||||
int main() {
|
||||
for (int x = 0; x <= 255; x++)
|
||||
cout << toHex(x) << endl;
|
||||
return 0;
|
||||
}
|
||||
83
GESP/Level4/GESP202306/manfen.cpp
Normal file
83
GESP/Level4/GESP202306/manfen.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 300;
|
||||
int b[N];
|
||||
vector<int> top16;
|
||||
int toDec(string s) {
|
||||
int sum = 0;
|
||||
if (s[0] >= 'A' && s[0] <= 'F')
|
||||
sum = (s[0] - 'A' + 10) * 16;
|
||||
else
|
||||
sum = (s[0] - '0') * 16;
|
||||
if (s[1] >= 'A' && s[1] <= 'F')
|
||||
sum += (s[1] - 'A' + 10);
|
||||
else
|
||||
sum += (s[1] - '0');
|
||||
return sum;
|
||||
}
|
||||
string toHex(int x){
|
||||
string res;
|
||||
while(x){
|
||||
int t = x % 16;
|
||||
if(t>=10)
|
||||
res+=t-10+'A';
|
||||
else res+=t+'0';
|
||||
x/=16;
|
||||
}
|
||||
reverse(res.begin(),res.end());
|
||||
return res;
|
||||
}
|
||||
char find(int q){
|
||||
int mi = INT_MAX, mp = 0;
|
||||
for (int i = 0; i < top16.size();i++){
|
||||
if(abs(q-top16[i])<mi){
|
||||
mi = abs(q-top16[i]);
|
||||
mp = i;
|
||||
}
|
||||
}
|
||||
if(mp>=10)
|
||||
return (char)(mp - 10 + 'A');
|
||||
return (char)(mp + '0');
|
||||
}
|
||||
string c[N];
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin>>n;
|
||||
for (int i = 1;i<=n;i++){
|
||||
string s;
|
||||
cin >> s;
|
||||
c[i] = s;
|
||||
for (int j = 0; j < s.size();j+=2){
|
||||
string x;
|
||||
x.push_back(s[j]);
|
||||
x.push_back(s[j + 1]);
|
||||
b[toDec(x)]++;
|
||||
}
|
||||
}
|
||||
for (int i = 1; i <= 16;i++){
|
||||
int mx = 0, mp = 0;
|
||||
for (int j = 0; j < 256;j++)
|
||||
if(b[j]>mx){
|
||||
mx = b[j];
|
||||
mp = j;
|
||||
}
|
||||
b[mp] = 0;
|
||||
top16.push_back(mp);
|
||||
}
|
||||
for (int i = 0; i < top16.size();i++)
|
||||
cout << toHex(top16[i]);
|
||||
cout << endl;
|
||||
for (int i = 1; i <= n;i++){
|
||||
string s = c[i];
|
||||
for (int j = 0; j < s.size();j+=2){
|
||||
string x;
|
||||
x.push_back(s[j]);
|
||||
x.push_back(s[j + 1]);
|
||||
int q=toDec(x);
|
||||
cout<<find(q);
|
||||
}
|
||||
cout<<endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
27
GESP/Level4/GESP202309/4_1.cpp
Normal file
27
GESP/Level4/GESP202309/4_1.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
/*
|
||||
2
|
||||
8 1362
|
||||
16 3F0
|
||||
*/
|
||||
int main() {
|
||||
int T;
|
||||
cin >> T;
|
||||
while (T--) {
|
||||
int k;
|
||||
string s;
|
||||
int res = 0;
|
||||
cin >> k >> s; // k进制,s是k进制的一个数
|
||||
for (int i = 0; i < s.size(); i++) {
|
||||
int x = 0;
|
||||
if (s[i] >= 'A')
|
||||
x = s[i] - 'A' + 10;
|
||||
else
|
||||
x = s[i] - '0';
|
||||
res = res * k + x;
|
||||
}
|
||||
cout << res << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
53
GESP/Level4/GESP202309/4_2.cpp
Normal file
53
GESP/Level4/GESP202309/4_2.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
typedef long long LL;
|
||||
const int N = 110;
|
||||
int a[N], al;
|
||||
|
||||
string b[N];
|
||||
int bl;
|
||||
|
||||
int main() {
|
||||
LL n;
|
||||
cin >> n;
|
||||
|
||||
if (n == 0) {
|
||||
cout << "00";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
while (n) {
|
||||
int x = n % 2;
|
||||
n /= 2;
|
||||
a[++al] = x;
|
||||
}
|
||||
// 补全零
|
||||
al = ceil(1.0 * al / 7) * 7;
|
||||
|
||||
for (int i = al; i > 1; i -= 7) {
|
||||
string s = "";
|
||||
for (int j = i; j > i - 7; j--)
|
||||
s = s + to_string(a[j]);
|
||||
|
||||
if (i == 7)
|
||||
b[++bl] = "1" + s;
|
||||
else
|
||||
b[++bl] = "0" + s;
|
||||
}
|
||||
|
||||
// 2进制4位一组生成16进制数
|
||||
for (int i = bl; i >= 1; i--) {
|
||||
// cout << b[i] << endl;
|
||||
for (int j = 0; j < b[i].size(); j += 4) {
|
||||
int x = (b[i][j] - '0') * 8 + (b[i][j + 1] - '0') * 4 +
|
||||
(b[i][j + 2] - '0') * 2 + (b[i][j + 3] - '0');
|
||||
if (x >= 10)
|
||||
cout << char(x - 10 + 'A');
|
||||
else
|
||||
cout << x;
|
||||
}
|
||||
cout << " ";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
GESP/Level4/GESP202309/GESP九月四级C++真题.pdf
Normal file
BIN
GESP/Level4/GESP202309/GESP九月四级C++真题.pdf
Normal file
Binary file not shown.
44
GESP/Level4/GESP202309/manfenti.cpp
Normal file
44
GESP/Level4/GESP202309/manfenti.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
typedef long long LL;
|
||||
const int N = 110;
|
||||
int a[N], al;
|
||||
|
||||
string b[N];
|
||||
int bl;
|
||||
int main(){
|
||||
LL n;
|
||||
cin>>n;
|
||||
if(n==0){
|
||||
cout<<"00"<<endl;
|
||||
return 0;
|
||||
}
|
||||
while(n){
|
||||
int x = n % 2;
|
||||
n /= 2;
|
||||
a[++al] = x;
|
||||
}
|
||||
al = ceil(1.0 * al / 7) * 7;
|
||||
for (int i = al; i > 1;i-=7){
|
||||
string s = "";
|
||||
for (int j = i; j > i - 7;j--)
|
||||
s =s+ to_string(a[j]);
|
||||
|
||||
if(i == 7)
|
||||
b[++bl] = "1"+s;
|
||||
else
|
||||
b[++bl] = "0"+s;
|
||||
}
|
||||
for (int i = bl;i>=1;i--){
|
||||
for (int j = 0; j < b[i].size();j+=4){
|
||||
int x = (b[i][j] - '0') * 8 + (b[i][j + 1] - '0') * 4
|
||||
+ (b[i][j + 2] - '0') * 2 + (b[i][j + 3] - '0');
|
||||
if(x>=10)
|
||||
cout << char(x - 10 + 'A');
|
||||
else
|
||||
cout << x;
|
||||
}
|
||||
cout << " ";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
61
GESP/Level4/GESP202309/test.cpp
Normal file
61
GESP/Level4/GESP202309/test.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
int a[N], al;
|
||||
string s[N];
|
||||
int sl;
|
||||
|
||||
// 2进制转16进制 0011 1100
|
||||
char get(string x) { // x 必须是4位一组的01数字 --> E B A
|
||||
int sum = 0;
|
||||
int base = 1;
|
||||
for (int i = x.size() - 1; i >= 0; i--) {
|
||||
sum += (x[i] - '0') * base;
|
||||
base *= 2;
|
||||
}
|
||||
if (sum >= 10)
|
||||
return (char)(sum - 10 + 'A');
|
||||
return (char)(sum + '0');
|
||||
}
|
||||
|
||||
// x=0000 0111
|
||||
// 0E
|
||||
string getHex(string x) { // 0E FE AC
|
||||
string a = x.substr(0, 4); // 前4个
|
||||
string b = x.substr(4, 4); // 后4个
|
||||
string c;
|
||||
c.push_back(get(a));
|
||||
c.push_back(get(b));
|
||||
return c;
|
||||
}
|
||||
|
||||
int main() {
|
||||
long long n = 987654321012345678;
|
||||
while (n) {
|
||||
int x = n % 2;
|
||||
n /= 2;
|
||||
a[++al] = x;
|
||||
}
|
||||
// 需要添加若干0来完成补位,需要添加多少个?
|
||||
int x = 7 - al % 7;
|
||||
if (al % 7 == 0)
|
||||
x = 0;
|
||||
al += x;
|
||||
|
||||
for (int i = al; i >= 1; i -= 7) { // 每一组
|
||||
string q = "";
|
||||
if (i == 7)
|
||||
q = q + "1";
|
||||
else
|
||||
q = q + "0";
|
||||
for (int j = 0; j < 7; j++) // 每一个
|
||||
q = q + to_string(a[i - j]);
|
||||
|
||||
s[++sl] = q;
|
||||
}
|
||||
|
||||
for (int i = sl; i; i--)
|
||||
cout << getHex(s[i]) << " ";
|
||||
|
||||
return 0;
|
||||
}
|
||||
32
GESP/Level4/GESP202312/4_1.cpp
Normal file
32
GESP/Level4/GESP202312/4_1.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
map<string, string> dict;
|
||||
int main() {
|
||||
int N;
|
||||
cin >> N;
|
||||
while (N--) {
|
||||
string word1, word2;
|
||||
cin >> word1 >> word2;
|
||||
dict[word1] = word2;
|
||||
}
|
||||
string content, word = "";
|
||||
cin >> content;
|
||||
content += "\n";
|
||||
|
||||
for (int i = 0; i < content.size(); i++) {
|
||||
if (content[i] >= 'a' && content[i] <= 'z')
|
||||
word += content[i];
|
||||
else { // 遇到符号,就停止下来看看刚才是不是拼接出了新的单词
|
||||
if (word != "") {
|
||||
if (dict.count(word))
|
||||
cout << dict[word];
|
||||
else
|
||||
cout << "UNK";
|
||||
word = "";
|
||||
}
|
||||
// 输出符号
|
||||
cout << content[i];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
24
GESP/Level4/GESP202312/4_2.cpp
Normal file
24
GESP/Level4/GESP202312/4_2.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 100005;
|
||||
int a[N];
|
||||
int b[N], bl = 1;
|
||||
int n;
|
||||
int ans;
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
for (int i = 1; i <= n; i++)
|
||||
scanf("%d", &a[i]);
|
||||
|
||||
for (int i = 1; i <= n; i++)
|
||||
scanf("%d", &b[i]);
|
||||
|
||||
sort(a + 1, a + n + 1);
|
||||
sort(b + 1, b + n + 1);
|
||||
|
||||
for (int i = 1; i <= n; i++)
|
||||
if (a[i] > b[bl])
|
||||
++ans, ++bl;
|
||||
printf("%d\n", ans);
|
||||
return 0;
|
||||
}
|
||||
BIN
GESP/Level4/GESP202312/GESP12月C++七级真题.pdf
Normal file
BIN
GESP/Level4/GESP202312/GESP12月C++七级真题.pdf
Normal file
Binary file not shown.
BIN
GESP/Level4/GESP202312/GESP12月C++五级真题.pdf
Normal file
BIN
GESP/Level4/GESP202312/GESP12月C++五级真题.pdf
Normal file
Binary file not shown.
BIN
GESP/Level4/GESP202312/GESP12月C++八级真题.pdf
Normal file
BIN
GESP/Level4/GESP202312/GESP12月C++八级真题.pdf
Normal file
Binary file not shown.
BIN
GESP/Level4/GESP202312/GESP12月C++六级真题.pdf
Normal file
BIN
GESP/Level4/GESP202312/GESP12月C++六级真题.pdf
Normal file
Binary file not shown.
BIN
GESP/Level4/GESP202312/GESP12月C++四级真题.pdf
Normal file
BIN
GESP/Level4/GESP202312/GESP12月C++四级真题.pdf
Normal file
Binary file not shown.
BIN
GESP/Level4/GESP202403/GESP2024年3月4级.pdf
Normal file
BIN
GESP/Level4/GESP202403/GESP2024年3月4级.pdf
Normal file
Binary file not shown.
51
GESP/Level4/GESP202406/2024062902_1.cpp
Normal file
51
GESP/Level4/GESP202406/2024062902_1.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 10010;
|
||||
int T;
|
||||
int a[N];
|
||||
int n;
|
||||
|
||||
/*
|
||||
2
|
||||
3
|
||||
1 2 4
|
||||
|
||||
5
|
||||
1 2 3 4 5
|
||||
*/
|
||||
bool check() {
|
||||
//<2F><><EFBFBD><EFBFBD>a[1]~a[n]<5D><>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20><>ǰö<C7B0>ٵ<EFBFBD><D9B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a[i]
|
||||
// <20>жϵ<D0B6>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>a[i]<5D>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ҫ<EFBFBD>ܿ<EFBFBD><DCBF>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>Լ<EFBFBD><D4BC>϶<EFBFBD><CFB6><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC>ı<EFBFBD><C4B1><EFBFBD>
|
||||
// <09><><EFBFBD><EFBFBD>һȦ<D2BB><EFBFBD><F3A3ACB7><EFBFBD>a[i]<5D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵı<D6B5><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>true
|
||||
// <09><><EFBFBD><EFBFBD>һȦ<D2BB><EFBFBD><F3A3ACB7><EFBFBD>a[i]<5D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵı<D6B5><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>i++
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><D6A3><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD>false
|
||||
for (int i = 1; i <= n; i++) {
|
||||
bool flag = false;//Ĭ<><C4AC>a[i]<5D>Ǻ<EFBFBD><C7BA>õ<EFBFBD>
|
||||
for (int j = 1; j <= n; j++) {
|
||||
if (a[i] % a[j]) { //a[i]<5D><><EFBFBD><EFBFBD>a[j]<5D>ı<EFBFBD><C4B1><EFBFBD>,ôa[i]<5D>Ǹ<EFBFBD><C7B8><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a[j]<5D><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
flag = true;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м䱻<D0BC><E4B1BB><EFBFBD>ϵģ<CFB5>Ҳ<EFBFBD><D2B2><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a[i]
|
||||
break;
|
||||
}
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (!flag)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> T;
|
||||
while (T--) {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> a[i];
|
||||
|
||||
if (check())
|
||||
cout << "YES" << endl;
|
||||
else
|
||||
cout << "NO" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
7
GESP/Level4/GESP202406/2024062902_2.cpp
Normal file
7
GESP/Level4/GESP202406/2024062902_2.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
GESP/Level4/GESP202406/4.pdf
Normal file
BIN
GESP/Level4/GESP202406/4.pdf
Normal file
Binary file not shown.
BIN
GESP/Level4/GESP202406/GESP 3级 20240629.docx
Normal file
BIN
GESP/Level4/GESP202406/GESP 3级 20240629.docx
Normal file
Binary file not shown.
9
GESP/Level4/GESP202406/信奥经验总结.txt
Normal file
9
GESP/Level4/GESP202406/信奥经验总结.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
1、看数据范围,最小最大都要测试一下,自己模拟样例。
|
||||
|
||||
2、看数据范围,评估是不是能用N^2级别的算法,最大1e5,否则就要思考是不是求最大或最小。
|
||||
|
||||
3、用纸和笔,把题目放在纸上,仔细思考每一步是如何变化的,找出变化规律和潜在的因素,再编码。
|
||||
ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
DEFGHIJKLMNOPQRSTUVWXYZACD
|
||||
|
||||
4、正向思考法,思考自己怎么才能一步步解决,而不是看别人的代码,看完更懵。
|
||||
36
GESP/Level4/GESP202409/20240906_3_1.cpp
Normal file
36
GESP/Level4/GESP202409/20240906_3_1.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N=10010;
|
||||
int a[N];
|
||||
|
||||
|
||||
int main(){
|
||||
int T;
|
||||
cin>>T;
|
||||
while(T--){
|
||||
int n;
|
||||
cin>>n;
|
||||
int sum=0;
|
||||
for(int i=1;i<=n;i++){
|
||||
cin>>a[i];
|
||||
sum+=a[i];
|
||||
}
|
||||
|
||||
int sum2=0;
|
||||
int flag=0;
|
||||
|
||||
for(int i=1;i<=n;i++){
|
||||
sum2+=a[i];
|
||||
if(sum2*2==sum){
|
||||
cout<<"Yes"<<endl;
|
||||
flag=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(flag==0) cout<<"No"<<endl;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
38
GESP/Level4/GESP202409/20240906_3_2.cpp
Normal file
38
GESP/Level4/GESP202409/20240906_3_2.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
//<2F>ж<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2>ǻ<EFBFBD><C7BB>Ĵ<EFBFBD>
|
||||
bool isHuiWen(string s){
|
||||
if(s.size()<2) return false;
|
||||
for(int i=0;i<s.size()/2;i++)
|
||||
if(s[i]!=s[s.size()-1-i]) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int T;
|
||||
cin>>T;
|
||||
|
||||
while(T--){
|
||||
string s;
|
||||
cin>>s;
|
||||
|
||||
int flag=0;
|
||||
//ö<>ٵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>Ӵ<EFBFBD><D3B4>Ľ<EFBFBD>βλ<CEB2><CEBB>
|
||||
for(int i=0;i<s.size();i++){
|
||||
string s1,s2;
|
||||
for(int j=0;j<=i;j++) s1+=s[j];//ƴ<>ӵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>Ӵ<EFBFBD>
|
||||
for(int j=i+1;j<s.size();j++) s2+=s[j];//ƴ<>ӵڶ<D3B5><DAB6><EFBFBD><EFBFBD>Ӵ<EFBFBD>
|
||||
//cout<<"s1="<<s1<<",s2="<<s2<<endl;
|
||||
if(isHuiWen(s1) && isHuiWen(s2)){
|
||||
cout<<"Yes"<<endl;
|
||||
flag=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(flag==0) cout<<"No"<<endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
77
GESP/Level4/GESP202409/20240906_4_1.cpp
Normal file
77
GESP/Level4/GESP202409/20240906_4_1.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
|
||||
//ע<>⣺n,mһ<6D><D2BB>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊcheck() <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD>
|
||||
int n, m;
|
||||
int a[N][N];
|
||||
|
||||
/*
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
3
|
||||
1 4
|
||||
0110
|
||||
5 5
|
||||
00000
|
||||
01100
|
||||
01100
|
||||
00001
|
||||
01100
|
||||
5 5
|
||||
00000
|
||||
01100
|
||||
01110
|
||||
00001
|
||||
01100
|
||||
|
||||
*/
|
||||
|
||||
bool check() {
|
||||
//0<><30><EFBFBD><EFBFBD> 1<><31><EFBFBD><EFBFBD>
|
||||
if (n < 4 || m < 4 ) //<2F><><EFBFBD><EFBFBD>4<EFBFBD><34>4<EFBFBD>У<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3>ⲽ<EFBFBD><E2B2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>©
|
||||
return false;
|
||||
|
||||
int s1 = 0, s4 = 0;
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
s1 += a[1][i];//<2F><>һ<EFBFBD>еĺ<D0B5>
|
||||
s4 += a[4][i];//<2F><><EFBFBD><EFBFBD><EFBFBD>еĺ<D0B5>
|
||||
}
|
||||
|
||||
if (s1 || s4)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD>ȫ<EFBFBD>ǰ<EFBFBD>ɫ
|
||||
return false;
|
||||
|
||||
//<2F><>2<EFBFBD>У<EFBFBD><D0A3><EFBFBD>3<EFBFBD><33>
|
||||
if (a[2][1] || a[2][4])//(2,1),(2,4)<29><><EFBFBD><EFBFBD><EFBFBD>Ǻ<EFBFBD>ɫ<EFBFBD><C9AB>
|
||||
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ע<>⣺<EFBFBD><E2A3BA><EFBFBD><EFBFBD>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD>Եģ<D4B5><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><C4BE>ǿ<EFBFBD><C7BF>Ե<EFBFBD>
|
||||
return false;
|
||||
if (!a[2][2] || !a[2][3])
|
||||
return false;
|
||||
|
||||
|
||||
if (a[3][1] || a[3][4])
|
||||
return false;
|
||||
if (!a[3][2] || !a[3][3])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int T;
|
||||
cin >> T;
|
||||
while (T--) {
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
string s;//<2F><>Ϊ01<30>м<EFBFBD><D0BC>ո<DEBF><D5B8><EFBFBD>ʹ<EFBFBD><CAB9>string<6E><67><EFBFBD>ж<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ٷֲ<D9B7><D6B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>a[N][N]<5D><>
|
||||
cin >> s;
|
||||
for (int j = 1; j <= m; j++)
|
||||
a[i][j] = s[j - 1] - '0';//Ҫע<D2AA><D7A2>string<6E>±<EFBFBD><C2B1>Ǵ<EFBFBD>0<EFBFBD><30>ʼ<EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>j<EFBFBD><6A>Ҫ<EFBFBD><D2AA>1
|
||||
}
|
||||
|
||||
if (check())
|
||||
cout << "Yes" << endl;
|
||||
else
|
||||
cout << "No" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
29
GESP/Level4/GESP202409/20240906_4_2.cpp
Normal file
29
GESP/Level4/GESP202409/20240906_4_2.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
int n;
|
||||
const int N = 10010;
|
||||
int a[N];
|
||||
/*
|
||||
5
|
||||
3 4 5 2 1
|
||||
3
|
||||
4 5
|
||||
3 4
|
||||
1 3
|
||||
*/
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> a[i];
|
||||
|
||||
int T;
|
||||
cin >> T;
|
||||
while (T--) {
|
||||
int l, r;
|
||||
cin >> l >> r;
|
||||
sort(a + l, a + r + 1);
|
||||
}
|
||||
for (int i = 1; i <= n; i++)
|
||||
cout << a[i] << " ";
|
||||
return 0;
|
||||
}
|
||||
BIN
GESP/Level4/GESP202409/3级.pdf
Normal file
BIN
GESP/Level4/GESP202409/3级.pdf
Normal file
Binary file not shown.
BIN
GESP/Level4/GESP202409/4级.pdf
Normal file
BIN
GESP/Level4/GESP202409/4级.pdf
Normal file
Binary file not shown.
67
GESP/Level4/GESP202409/未命名1.cpp
Normal file
67
GESP/Level4/GESP202409/未命名1.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
const int N = 256;
|
||||
int b[N]; // 桶
|
||||
int a[17], al;
|
||||
|
||||
string c[N];
|
||||
int cl;
|
||||
int get(char x) {
|
||||
if (x >= '0' && x <= '9')
|
||||
return x - '0';
|
||||
return x - 'A' + 10;
|
||||
}
|
||||
|
||||
int toDec(char a, char b) { return get(a) * 16 + get(b); }
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
string s;
|
||||
cin >> s;
|
||||
c[++cl] = s; // 原始数组保存下来
|
||||
// 字符串长度 s.size()
|
||||
for (int j = 0; j < s.size(); j += 2) {
|
||||
int idx = toDec(s[j], s[j + 1]); // 对应的十进制数值
|
||||
b[idx]++; // 维护桶
|
||||
}
|
||||
}
|
||||
|
||||
// 猴子选大王共16次
|
||||
for (int i = 1; i <= 16; i++) {
|
||||
int mx = -1, mp = 0;
|
||||
for (int j = 0; j < N; j++) {
|
||||
if (b[j] > mx) {
|
||||
mx = b[j];
|
||||
mp = j;
|
||||
}
|
||||
}
|
||||
a[++al] = mp; // 本轮次找到的大王位置是mp,记录下来到a数组中去
|
||||
b[mp] = -1; // 避免重复选,把大王出列
|
||||
}
|
||||
|
||||
// 遍历原始数组
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int j = 0; j < c[i].size(); j += 2) {
|
||||
int old = toDec(c[i][j], c[i][j + 1]);
|
||||
// 需要与b数组中的每一个数值进行对比,看看与哪个数值的绝对值差最小,也就是与谁最接近`
|
||||
int mi = INT_MAX,
|
||||
mp = 0; // mi最小的差绝对值,mp就是最小差绝对值所在的位置号
|
||||
for (int k = 1; k <= 16; k++) {
|
||||
int x = b[k];
|
||||
int d = abs(x - old);
|
||||
if (d < mi) {
|
||||
mp = k;
|
||||
mi = d;
|
||||
}
|
||||
}
|
||||
if (mp >= 10)
|
||||
cout << mp - 10 + 'A';
|
||||
else
|
||||
cout << mp;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
21
GESP/Level4/GESP202412/1.cpp
Normal file
21
GESP/Level4/GESP202412/1.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 3010;
|
||||
int a[N];
|
||||
set<int> s;
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
a[1] = 1;
|
||||
for (int k = 2; k <= n; k++) {
|
||||
if (a[k - 1] - k > 0 && s.count(a[k - 1] - k) == 0) {
|
||||
a[k] = a[k - 1] - k;
|
||||
s.insert(a[k - 1] - k);
|
||||
} else
|
||||
a[k] = a[k - 1] + k;
|
||||
}
|
||||
sort(a + 1, a + n + 1);
|
||||
for (int i = 1; i <= n; i++)
|
||||
cout << a[i] << " ";
|
||||
return 0;
|
||||
}
|
||||
34
GESP/Level4/GESP202412/2.cpp
Normal file
34
GESP/Level4/GESP202412/2.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
string s[N];
|
||||
int main() {
|
||||
// 从文本文件中获取输入
|
||||
#ifndef ONLINE_JUDGE
|
||||
freopen("4.in", "r", stdin);
|
||||
#endif
|
||||
int T;
|
||||
cin >> T;
|
||||
while (T--) {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> s[i];
|
||||
// 对字符串进行排序
|
||||
sort(s + 1, s + n + 1);
|
||||
// 拼接成一个长的字符串
|
||||
string t = "";
|
||||
for (int i = 1; i <= n; i++)
|
||||
t = t + s[i];
|
||||
|
||||
bool isHeFa = true;
|
||||
for (int i = 1; i < t.size(); i++) {
|
||||
if (t[i] < t[i - 1]) {
|
||||
isHeFa = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
cout << isHeFa << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
BIN
GESP/Level4/GESP202412/20241207_4.pdf
Normal file
BIN
GESP/Level4/GESP202412/20241207_4.pdf
Normal file
Binary file not shown.
10
GESP/Level4/GESP202412/4.in
Normal file
10
GESP/Level4/GESP202412/4.in
Normal file
@@ -0,0 +1,10 @@
|
||||
3
|
||||
3
|
||||
aa
|
||||
ac
|
||||
de
|
||||
2
|
||||
aac
|
||||
bc
|
||||
1
|
||||
gesp
|
||||
BIN
GESP/Level4/GESP202503/202503四级.pdf
Normal file
BIN
GESP/Level4/GESP202503/202503四级.pdf
Normal file
Binary file not shown.
4
GESP/Level4/GESP202503/T1.in
Normal file
4
GESP/Level4/GESP202503/T1.in
Normal file
@@ -0,0 +1,4 @@
|
||||
3 5
|
||||
.....
|
||||
.#..#
|
||||
.....
|
||||
68
GESP/Level4/GESP202503/T1_1.cpp
Normal file
68
GESP/Level4/GESP202503/T1_1.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 1010;
|
||||
int a[N][N];
|
||||
int ans;
|
||||
int n, m;
|
||||
/*
|
||||
3 5
|
||||
.....
|
||||
.#..#
|
||||
.....
|
||||
|
||||
答案:
|
||||
11
|
||||
*/
|
||||
|
||||
// 判断一个位置是不是荒地
|
||||
int check(int x, int y) {
|
||||
// 对于⼀块不存在杂物的荒地, 该荒地可以开垦当且仅当其上下左右四个⽅向相邻的格⼦均不存在杂物
|
||||
if (a[x][y] || a[x - 1][y] || a[x + 1][y] || a[x][y - 1] || a[x][y + 1])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 计算有多少个荒地
|
||||
int countHuangDi() {
|
||||
int sum = 0;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= m; j++)
|
||||
if (check(i, j))
|
||||
sum++;
|
||||
return sum;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= m; j++) {
|
||||
char c;
|
||||
cin >> c;
|
||||
if (c == '#')
|
||||
a[i][j] = 1; // a[i][j]=1:杂物, a[i][j]=0:荒地
|
||||
}
|
||||
|
||||
// 在任何一个杂物位置也不修改的情况下,计算一下荒地的个数
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= m; j++)
|
||||
if (check(i, j))
|
||||
ans++;
|
||||
|
||||
// 每个原来是杂物的位置 都有可能更改为荒地,然后计算在这样修改的情况下,荒地的个数
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= m; j++) {
|
||||
if (a[i][j]) {
|
||||
// 尝试把i,j位置改为荒地
|
||||
a[i][j] = 0;
|
||||
int sum = countHuangDi();
|
||||
ans = max(ans, sum);
|
||||
// 恢复现场
|
||||
a[i][j] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
||||
72
GESP/Level4/GESP202503/T1_2.cpp
Normal file
72
GESP/Level4/GESP202503/T1_2.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 1010;
|
||||
typedef pair<int, int> PII;
|
||||
vector<PII> vec;
|
||||
int a[N][N];
|
||||
int ans;
|
||||
int n, m;
|
||||
|
||||
int mx; // 最多带来几个荒地的价值
|
||||
/*
|
||||
3 5
|
||||
.....
|
||||
.#..#
|
||||
.....
|
||||
|
||||
答案:
|
||||
11
|
||||
*/
|
||||
|
||||
// 判断一个位置是不是荒地
|
||||
int check(int x, int y) {
|
||||
// 对于⼀块不存在杂物的荒地, 该荒地可以开垦当且仅当其上下左右四个⽅向相邻的格⼦均不存在杂物
|
||||
if (a[x][y] || a[x - 1][y] || a[x + 1][y] || a[x][y - 1] || a[x][y + 1])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
freopen("T1.in", "r", stdin);
|
||||
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= m; j++) {
|
||||
char c;
|
||||
cin >> c;
|
||||
if (c == '#') {
|
||||
a[i][j] = 1; // a[i][j]=1:杂物, a[i][j]=0:荒地
|
||||
vec.push_back({i, j});
|
||||
}
|
||||
}
|
||||
|
||||
// 在任何一个杂物位置也不修改的情况下,计算一下荒地的个数
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= m; j++)
|
||||
if (check(i, j))
|
||||
ans++;
|
||||
|
||||
// 每个原来是杂物的位置 都有可能更改为荒地,然后计算在这样修改的情况下,荒地的个数
|
||||
for (auto p : vec) {
|
||||
int i = p.first, j = p.second;
|
||||
// 尝试把i,j位置改为荒地
|
||||
a[i][j] = 0;
|
||||
|
||||
int sum = check(i, j);
|
||||
if (i - 1 >= 1)
|
||||
sum += check(i - 1, j);
|
||||
if (i + 1 <= n)
|
||||
sum += check(i + 1, j);
|
||||
if (j - 1 >= 1)
|
||||
sum += check(i, j - 1);
|
||||
if (j + 1 <= m)
|
||||
sum += check(i, j + 1);
|
||||
|
||||
mx = max(mx, sum);
|
||||
// 恢复现场
|
||||
a[i][j] = 1;
|
||||
}
|
||||
|
||||
cout << ans + mx << endl;
|
||||
return 0;
|
||||
}
|
||||
19
GESP/Level4/GESP202503/T2.cpp
Normal file
19
GESP/Level4/GESP202503/T2.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 510;
|
||||
int n, m;
|
||||
int a[N][N];
|
||||
int ans;
|
||||
int main() {
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= m; j++)
|
||||
cin >> a[i][j];
|
||||
|
||||
for (int i = 1; i < n; i++)
|
||||
for (int j = 1; j < m; j++)
|
||||
if (a[i][j] * a[i + 1][j + 1] == a[i + 1][j] * a[i][j + 1])
|
||||
ans++;
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user