打印
[其他]

灵动集训

[复制链接]
359|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
l63t89|  楼主 | 2021-1-27 18:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
集训第一天
A题
#include<stdio.h>
int calc(int k,int b);
int main()
{
int i,s;
for(i=2991;i<10000;i++)
{
s=i%10+(i/10)%10+(i/100)%10+(i/1000);
if(scalc(i,12)&&scalc(i,16))
printf("%d\n",i);
}
return 0;
}
int calc(int k,int b)
{
int a[5],i=0,sum=0,j;
while(k)
{
a=k%b;
k=k/b;
i++;
}
i–;
for(j=i; j>=0; j–)
sum+=a[j];
return sum;
}
这是道会做的题,感觉没什么难度,也没有什么困难。
B题
#include
#include
using namespace std;
const int N = 1e6 + 10;
char s[N], cnt;
int main() {
char c;
while(~scanf("%c", &c)) {
if((c >= ‘a’ && c <= ‘z’) || (c >= ‘A’ && c <= ‘Z’)) {
s[cnt++] = c;
} else {
if(cnt == 0) {
printf("%c", c);
continue;
}
if(s[0] == ‘a’ || s[0] == ‘e’ || s[0] == ‘i’ || s[0] == ‘o’ || s[0]
== ‘u’
|| s[0] == ‘A’ || s[0] == ‘E’ || s[0] == ‘I’ || s[0] == ‘O’ ||
s[0] == ‘U’) {
for(int i = 0; i < cnt; i++) {
printf("%c", s);
}
printf(“ay%c”, c);
} else {
for(int i = 1; i < cnt; i++) {
printf("%c", s);
}
printf("%cay%c", s[0], c);
}
cnt = 0;
}
}
return 0;
}
刚开始不会做,看了答案知道了思路。重点在于判断是不是字母和判断完整的单词。
难点在于如何改成c语言

使用特权

评论回复
沙发
l63t89|  楼主 | 2021-1-27 18:38 | 只看该作者
C题
#include
#include
using namespace std;
char mp[3][3];
int x, o;
int flag;
bool cal(char tar) {
for (int i = 0; i < 3; ++i) {
if (mp[0][i] == tar) {
if (mp[1][i]==tar && mp[2][i]==tar) {
return true;
}
}
}
for (int i = 0; i < 3; ++i) {
if (mp[i][0] == tar) {
if (mp[i][1]==tar && mp[i][2]==tar) {
return true;
}
}
}
if (mp[0][0]==tar && mp[1][1]==tar && mp[2][2]==tar) {
return true;
}
if (mp[0][2]==tar && mp[1][1]tar && mp[2][0]tar) {
return true;
}
return false;
}
int main() {
int n;
cin >> n;
while (n–) {
flag = x = o = 0;
for (int i = 0; i < 3; ++i) {
scanf("%s", mp[i]);
}
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
if (mp[i][j] == ‘X’) {
x++;
}
else if (mp[i][j] == ‘O’) {
o++;
}
}
}
if (x >= o) {
if (x == o) {
flag = cal(‘X’) ? 0 : 1;
}
else if (x - o == 1) {
flag = cal(‘O’) ? 0 : 1;
}
else {
flag = 0;
}
}
else {
flag = 0;
}
printf("%s\n", flag1 ? “yes” : “no”);
}
return 0;
}
这题刚开始也不会做,看了答案后有了一点思路。这题主要是要把思路理清,条件一定要考虑全面。
难点在于不知道怎么改成c语言。
D题
#include <bits/stdc++.h>
using namespace std;
const long long FACT1 = 10000;
const long long FACT2 = 6227020800;
const int N = 13;
long long fact[N + 1];
void init()
{
fact[0] = 1;
for(int i=1; i<=N; i++) {
fact[i] = i * fact[i - 1];
}
}
int main()
{
init();
int n;
while(~scanf("%d", &n))
if(n > N || (n < 0 && (n * -1 & 1) 1))
printf(“Overflow!\n”);
else if(fact[n] < FACT1 || (n < 0 && (n * -1 & 1) == 0))
printf(“Underflow!\n”);
else
printf("%lld\n", fact[n]);
return 0;
}
开始也不会做,看了答案后还行。感觉题目迷惑性很大但读懂后就是简单的递归。
难点在于不知道怎么改成c语言。
E题
#include
#include
using namespace std;
int f[21][21][21];
int w(int a,int b,int c){
if (a <= 0 || b <= 0 || c <= 0)return 1;
if (a > 20 || b > 20 || c > 20)return w(20, 20, 20);
if (f[a][b][c])return f[a][b][c];
return f[a][b][c] = w(a - 1, b, c) + w(a - 1, b - 1, c) + w(a -
1, b, c - 1) - w(a - 1, b - 1, c - 1);
}
int main() {
memset(f, 0, sizeof(f));
int a, b, c;
while (cin >> a >> b >> c) {
if (a == -1 && b == -1 && c == -1)break;
cout <<“w(”<<a<<", “<<b<<”, “<<c<<”) = “<< w(a, b, c) <<
endl;
}
return 0;
}
这题刚开始也不会做,听了讲解后发现是递归,重点在于去掉重复的计算,节省时间。
难点在于不知道怎么改成c语言。

使用特权

评论回复
板凳
l63t89|  楼主 | 2021-1-27 18:38 | 只看该作者
F题
#include
using namespace std;
typedef long long ll;
int F(int n) {
return n % 10 ? n % 10 : !n ? 0 : F(n / 10);
}
ll S(int p, int q) {
ll ans=0;
while (p <= q)
ans += F(p++);
return ans;
}
ll function(int p,int q) {
if (q - p < 9)return S(p, q);
ll sum = 0;
int l = (p / 10 + 1) * 10, r = (q / 10) * 10;
sum += S(p, l - 1);
sum += S(r + 1, q);
sum += ((r - l) / 10) * S(1, 9);
return sum + function(l / 10, r / 10);
}
int main() {
int p, q;
while (cin >> p >> q) {
if (p == -1 && q == -1)break;
cout << function(p, q) << endl;
}
return 0;
}
完全没看懂,这题跳过,以后水平上去了再说。
G题
#include
#include
#include
#include
#include
using namespace std;
const int N = 1e6 + 7;
const int inf = 0x3f3f3f3f;
struct node {
char name[1007];
int subi[4];
int timei[4];
int solved;
int time;
} team[N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
scanf(”%s", team[i].name);
for (int j = 0; j < 4; ++j) {
scanf("%d%d", &team[i].subi[j], &team[i].timei[j]);
if (team[i].timei[j]) {
team[i].solved++;
team[i].time += team[i].timei[j];
if (team[i].subi[j] > 1) {
team[i].time += ((team[i].subi[j]-1)<<4) +
((team[i].subi[j]-1)<<2);
}
}
}
}
node res;
res.solved = -1;
res.time = inf;
for (int i = 0; i < n; ++i) {
if ((team[i].solved>res.solved) || (team[i].solved==res.solved &&
team[i].time<res.time)) {
strcpy(res.name, team[i].name);
res.solved = team[i].solved;
res.time = team[i].time;
}
}
printf("%s %d %d", res.name, res.solved, res.time);
return 0;
}
这题不难,还可以,自己能勉强做出来。
结语:主要还是C++没有掌握,源代码读不懂,对题目的理解有一些障碍,需要尽快将C++补上。

使用特权

评论回复
地板
豌豆爹| | 2021-1-28 17:05 | 只看该作者
这些题很有参考价值,赞一个

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

85

主题

771

帖子

0

粉丝