第二届全国大学生算法设计与编程挑战赛(冬季赛)
只会做水题555 剩下的连题解也没看懂QAQ
目录
A 塔
签到
#include<iostream>
using namespace std;
int main()
{
char c1;
int n=26; //设定塔的层数为26
for(int i=1;i<=n;i++){ //对塔每一层按照规律进行构造。
//首先进行输出空格的操作:对于第i行,字符前面的空格个数为n-i个。
for(int j = 1;j<=n-i;j++)
cout<<" ";
for(int j=1;j<=i;j++){ //按照规律1,输出第1~第i个大写字母。
c1=j+'A'-1; //第j个大写字母为'A'+j-1
cout<<c1; //输出第j个大写字母
}
for(int j=i-1;j>=1;j--){ //按照规律1,输出第i-1~第1个大写字母,注意是倒序
c1=j+'A'-1;
cout<<c1;
}
cout<<endl;//第i行输出结束,进行换行。
}
return 0;
}
B 日记
签到
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
string s;
int main() {
s = "ibti lbtlovebte lbtlibtinbtnkbtkebtezbas jebte dosadnbtna "
"ovakbtkebtemibtijaxaszxdbtddbtddbtddbtddbtddbtd";
string res;
for (int i = 0; i < s.size(); i++) {
res.push_back(s[i]);
if (s[i] == 'l' || s[i] == 'i' || s[i] == 'n' || s[i] == 'k' ||
s[i] == 'e') {
i += 3;
}
}
cout << res << endl;
return 0;
}
C 哥布林
待补...
D 质数区间
待补...
E 神仙爱采药
贪心即可,如果背包满了,那么遇到1就把2换掉,否则就一直往背包里放即可
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
#define int LL
int v, num1, num2, res, now;
string s;
signed main() {
cin >> v;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '1') {
if (num1 + num2 * 2 < v) {
num1++;
now++;
} else {
if (num2) {
num2--;
num1++;
}
}
} else {
if (num1 + num2 * 2 + 2 <= v) {
num2++;
now++;
}
}
res += now;
}
cout << res << endl;
return 0;
}
F 但更爱字符串
模拟...
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int const MAXN = 2e5 + 10;
int n, m, T;
string s = "";
string s0 = "";
string t = "";
string s1 = "";
int main() {
int len = 0;
while (getline(cin, s0)) {
int f = 0;
int da = 0;
int flag = 0;
s0.push_back('
');
for (int i = 0; i < s0.size(); i++) {
if ((s0[i] >= 'A' && s0[i] <= 'Z') ||
(s0[i] >= 'a' && s0[i] <= 'z')) {
s = s + s0[i];
if (s0[i] >= 'A' && s0[i] <= 'Z') da++;
continue;
}
if (s[0] >= 'a' && s[0] <= 'z' || da > 1 || s.size() <= 1) {
if (len <= 1) {
f = 1;
cout << s1;
if (len == 1) cout << " ";
t = "";
s1 = "";
len = 0;
} else {
f = 1;
cout << t;
cout << " (" << s1 << ") ";
t = "";
s1 = "";
len = 0;
}
cout << s;
} else {
if (s0[i] == ' ') {
if (s0[i - 1] == ',' || s0[i - 1] == '.' ||
s0[i - 1] == '!') {
cout << " ";
continue;
}
t = t + s[0];
if (len >= 1) s1 += " ";
s1 = s1 + s;
len++;
f = 0;
} else {
if (len < 1) {
f = 1;
cout << s1;
if (len == 1) cout << " ";
t = "";
s1 = "";
len = 0;
cout << s;
} else {
f = 1;
t = t + s[0];
cout << t;
if (s != "," || s != ".") s1 = s1 + " " + s;
cout << " (";
cout << s1;
cout << ")";
t = "";
s1 = "";
len = 0;
}
}
}
if (f) cout << s0[i];
if (s0[i] >='a'&&s0[i] <='z'||s0[i] >='A'&&s0[i] <='Z')
f = 1;
s = "";
da = 0;
}
}
return 0;
}
贴个标程吧,感觉标程写的很清晰:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
vector <string> word;//存放单词和符号
bool bigletter(char c){//判断是不是大写字母
if(c>='A'&&c<='Z') return true;
return false;
}
bool smallletter(char c){//判断是不是小写字母
if (c>='a'&&c<='z') return true;
return false;
}
bool bigletterword(string s){//判断是不是word
if (!bigletter(s[0])) return false;
if (s.size()<=1) return false;
for (int i=1;i<s.size();i++){
if (!smallletter(s[i])) return false;
}
return true;
}
void work(){//处理每一个单词或符号
int n=word.size();
for (int i=0;i<n;i++){
int inow=i;
if (!bigletterword(word[i]))//如果不需要缩写则直接输出
cout<<word[i];
if (bigletterword(word[i])) {
if (i!=n-1){//最后一位要么跟着前面的缩写,要么就是只有一个符合的所以不用缩写
if (word[i+1]==" "&&bigletterword(word[i+2])){
int j;
for (j=i;j<n;j++){
if ((j-i)%2==0){
if (!bigletterword(word[j])){
j--;
break;
}
else cout<<word[j][0];
}
else if (word[j]!=" ") break;
}//j停在了最后符合要求的word的最后一位的后面一位
cout<<" (";
for (int k=i;k<j-1;k+=2)
cout<<word[k]<<' ';
cout<<word[j-1]<<')';
inow=j-1;//i直接跳过缩写的部分
}
else cout<<word[i];
}
else cout<<word[i];
}
i=inow;
}
}
int main(){
string s;
while(getline(cin,s)){
if (s.size()==0) break;//如果输入为空就停止
string w="";//存放单词
for (int i=0;i<s.size();i++){//循环s
if (bigletter(s[i])||smallletter(s[i])) w+=s[i];//如果是字母则直接压到s里
if (!bigletter(s[i])&&!smallletter(s[i])){//否则把单词压到word了,并把符号也压进去
word.push_back(w);
w="";
w+=s[i];
word.push_back(w);
w="";
}
}
word.push_back(w);//把最后一个单词压进去
work();
word.clear();//清空word
cout<<endl;
}
return 0;//完美结束
}
G 猫腥草争夺大战
状压DP,待补...
H 无限山河印的故事
倍增+字符串hash 待补...
I 奇怪的传输机增加了
模拟每一天的状态即可
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
double n, now;
int x, y;
const double eps = 1e-8;
// 和0做比较
int sgn(double x) {
if (fabs(x) < eps) return 0; // =0
if (x < 0)
return -1; // < 0
else
return 1; // > 0
}
int main() {
cin >> n >> x >> y;
now = n;
for (int i = 1; i <= y; i++) {
now = 2.0 * now / 3.0;
if (i >= x) {
now = min(n, now + (n / 2));
x = 1e5;
}
if(sgn(now-n/32)<0){
cout << "N0!" << endl;
printf("%d %.6lf
", i, now);
return 0;
}
}
cout << "YE5!" << endl;
printf("%.6lf
", now);
return 0;
}
J 奇怪的小鸭子也增加了
数学题
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
int A, B, a, b;
int main(){
cin >> A >> B >> a >> b;
int x = (A - a) / a / 2 + 1;
int y = (B - b) / b / 2 + 1;
cout << x * y << endl;
return 0;
}
K 关于哥俩好的数字这件事
暴力枚举数位和
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long LL;
#define int LL
vector<int> res[N];
int get(int x) {
int res = 0;
while (x) {
res += x % 10;
x /= 10;
}
return res;
}
signed main() {
for (int i = 1; i <= 1e7; i++) {
res[get(i)].push_back(i);
}
int n;
cin >> n;
if(n==1)
cout << 1 << endl;
else if (n <= 10) {
LL ress = 0;
for (int i = 0; i < n; i++) {
ress += res[n - 1][i];
}
cout << ress << endl;
} else if (n >= 11) {
LL ress = 1e18;
for (int j = 9; j <= 20;j++){
LL tmp = 0;
for (int i = 0; i < n; i++) tmp += res[j][i];
ress = min(ress, tmp);
}
cout << ress << endl;
}
return 0;
}
L 我们仍未知道那窝蛋的名字
待补...
M 出题人说这道题是一个签到题
签到
#include <bits/stdc++.h>
using namespace std;
int n;
signed main() {
cin >> n;
if (n == 1)
cout << "ADPC";
else
cout << "12345";
return 0;
}