26.8.14
声明
代码仅供参考,请勿抄袭!
题目信息: | 题目名称 | 难度 | 思路(没有/有一点/有) | 分数 | |:-:|:-:|:-:|:-:| | 数列找规律| 暂无评定| 有一点 | 40| | 小田的修行3 | 普及−| 有| 40| |MC |入门 | 没有 | 0| | biubiubiu | 暂无评定| 没有 | 20|
T2
题意:有一个由整数组成的数列,给定前6个数,找出数列规律,输入整数n,输出该数列的第n个数
WA代码:
#include <bits/stdc++.h>
using namespace std;
#define ing unsigned long long
#define endl '\n'
int a[1000005];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (int i = 1; i <= 6; i++){
cin >> a[i];
}
int n;
cin >> n;
cout << a[n];
return 0;
}
错因:看到题目没有思路,不知道怎么写,第二个样例更是看不懂
思路:经过老师的提醒,我发现计算部分有特定的关系:a[i] = a[i - 2] + (a[i - 2] - a[i - 4]);
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define ing unsigned long long
#define endl '\n'
int a[1000005];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (int i = 1; i <= 6; i++){
cin >> a[i];
}
int n;
cin >> n;
for (int i = 7; i <= n; i++){
a[i] = a[i - 2] + (a[i - 2] - a[i - 4]);
}
cout << a[n];
return 0;
}
T5
题意:得到了一个长度为 n 的数组,里面有 n 个数字,接下来会得到 q 次询问,每次询问会输入一个数字 x,如果 x 是任意a数组中的数字的倍数,他需要输出 Yes,否则需要输出 No。
思路:for循环遍历,输入a[i];for循环遍历,内部for循环,如果x 是a[t]的倍数,那么将标记加1,直接结束内部循环。最后进行判断,输出。
WA代码:
#include <bits/stdc++.h>
using namespace std;
#define ing unsigned long long
#define endl '\n'
int a[1005];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++){
cin >> a[i];
}
for (int i = 1; i <= q; i++){
int f = 0;
int m;
cin >> m;
for (int t = 1; t <= n; t++){
if (m % a[t] == 0){
f++;
break;
}
}
cout << (f != 0?"Yes":"No") << endl;
}
return 0;
}
错因:TLE超时,需要优化
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define ing unsigned long long
#define endl '\n'
const int N = 1e5 + 5;
int a[N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++){
int m;
cin >> m;
for (int bs = 1; bs * m <= 1e5; bs++){
a[m * bs] = 1;
}
}
for (int i = 1; i <= q; i++){
int b;
cin >> b;
if (a[b] == 1){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
}
return 0;
}
T6
题意:开一个 n×n 的方阵,现在有 m 个火把和 k 个萤石,分别放在 (x 1 ,y 1 )∼(x m ,y m ) 和 (o 1 ,p 1 )∼(o k ,p k ) 的位置,没有光并且没放东西的地方会生成怪物。问在这个方阵中有几个点会生成怪物
WA代码:没写
错因:没思路
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define ing unsigned long long
#define endl '\n'
int a[105][105];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, f;
cin >> n >> m >> f;
for (int i = 1; i <= m; i++){
int x, y;
cin >> x >> y;
for (int j = max(1, x - 1); j <= x + 1; j++){
for (int k = max(1, y - 1); k <= y + 1; k++){
a[j][k] = 1;
}
}
a[max(1, x-2)][y] = 1;
a[x+2][y] = 1;
a[x][max(1, y-2)] = 1;
a[x][y+2] = 1;
}
for (int i = 1; i <= f; i++){
int x, y;
cin >> x >> y;
for (int j = max(1, x - 2); j <= x + 2; j++){
for (int k = max(1, y - 2); k <= y + 2; k++){
a[j][k] = 1;
}
}
}
int sum = 0;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
sum += a[i][j];
}
}
cout << n * n - sum;
return 0;
}
T7
题意:玩游戏的草坪划成了 N×N 的矩阵,同时算出了K 个对手在草地上的位置,在这个游戏中,用一把枪向八个方向中的任意一个方向射出子弹,这八个方向分别是:正北,正南,正东,正西,东北,东南,西北,西南。 要算出有多少个位置可以让Bessie射到所有对手。Bessie 可以和她的某一个对手站在同一格子,这时候她可以射到和她同一格子的对手。
WA代码:没写
错因:没思路
AC代码:
#include <bits/stdc++.h>
using namespace std;
#define ing unsigned long long
#define endl '\n'
int a[105][105];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++){
int x, y;
cin >> x >> y;
for (int j = 1; j <= n; j++){
for (int k = 1; k <= n; k++){
if (abs(j - x) == abs(k - y) || j == x || k == y){
a[j][k]++;
}
}
}
}
int sum = 0;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
if (a[i][j] == m){
sum++;
}
}
}
cout << sum;
return 0;
}