A.lwy梦境中的斐波那契数列——诈骗签到题
f(1)=1;
f(n)=n+f(n-1);
f(2)=1+2;
递推可得f(n)=1+2+3+.......+n;
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define N 1000010
#define inf 0x3f3f3f3f
#define ll long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ull unsigned long long
#define mod 1000000007
int main()
{
ll n;
cin >> n;
ll m = 4399;
ll ans = 1;
n %= 4399;
//数据范围到了1e9,直接循环会T
ans = (1 + n) * (n / 2) % 4399;
if (n & 1) ans = (ans + n / 2 + 1) % 4399;
cout << ans;
return 0;
}
B.你还会想起这道题吗
简单模拟,遍历加上图中的点即可
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define N 1000010
#define inf 0x3f3f3f3f
#define ll long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ull unsigned long long
#define mod 1000000007
int a[100][100];
int main()
{
int n, m;
cin >> n;
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
//左对角线求和
if (i == j) ans += a[i][j];
//右对角线求和
if (i + j == n + 1) ans += a[i][j];
}
}
//若n为奇数,中心点会被加两次,需要去重
if (n & 1) {
int m = (n + 1) / 2;
ans -= a[m][m];
}
//左边界和右边界,不加上下端点
for (int i = 2; i < n; i++)
ans += a[i][1], ans += a[i][n];
//上边界和下边界,不加左右端点
for (int i = 2; i < n; i++)
ans += a[1][i], ans += a[n][i];
cout << ans;
return 0;
}
C.你还会想起这道题吗(another version)
同样模拟题,遍历每一个环,求最大值即可
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define N 1000010
#define inf 0x3f3f3f3f
#define ll long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ull unsigned long long
#define mod 1000000007
int a[501][501];
int main()
{
int n;
cin >> n;
ll ans = 0, res = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
}
}
int p = n;
//k是每次遍历的环与边界的距离,初始最外环,距离为0
int k = 0;
//从外环逐渐缩小,每次宽度都减二,当n<=0时,代表遍历结束
while (n > 0) {
res = 0;
//m是当前遍历环的上边界和左边界位置,l是右边界和下边界位置,p就是n
int m = k + 1;
int l = p - k;
//环上下边的数值和
for (int i = m; i <= l; i++)
res += a[m][i], res += a[l][i];
//环左右边界的数值和,此处从m+1到l-1;因为m和l位置的上面已经求过了
for (int i = m + 1; i < l; i++)
res += a[i][m], res += a[i][l];
//需要注意的是,当环缩小到一个方块时,上面的操作会将其加两边,所以应该特判一下
if (m == l) res = a[m][l];
ans = max(ans, res);
//环缩小,与边界距离k变大,环宽度n减二
k++;
n -= 2;
}
cout << ans;
return 0;
}
D.农场大户
开一个map存一下所有资源的数量即可
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define N 1000010
#define inf 0x3f3f3f3f
#define ll long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ull unsigned long long
#define mod 1000000007
map<string, ll>op;
int main()
{
//IOS;不开ios时间有点长
int n, m, z,k;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> z;
while (z--) {
string str;
cin >> str>>k;
op[str] += k;
}
}
ll ans = 0;
while (m--) {
string str;
cin >> str >> k;
ans = ans + op[str] * k;
}
cout << ans;
return 0;
}
E.一道较为复杂的签到题
程序员当然是秃子了,所以乘积必然为0;
F.n车摆放问题
前面填了k行,接下来一行就只有m-k个选项了
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define N 1000010
#define inf 0x3f3f3f3f
#define ll long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ull unsigned long long
#define mod 1000000007
int n, m;
int main()
{
cin >> n >> m;
cout << min(n, m) << "\n";
ll ans = 1;
for (int i = 0; i < min(n, m); i++) {
ans = ans * (max(n, m) - i);
}
cout << ans;
return 0;
}
G.美食
H.皮卡丘的梦幻之旅(easy version)
就三个,dfs就行了
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define N 1000010
#define inf 0x3f3f3f3f
#define ll long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ull unsigned long long
#define mod 1000000007
int n, m;
ll ans = 0;
int a[100];
void dfs(int k,int sum) {
if (sum == n) {
ans++;
return;
}
if (sum > n) return;
if (k > n) return;
for (int i = 1; i <= m; i++) {
dfs(i+1, sum + a[i]);
}
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= m; i++)
cin >> a[i];
dfs(1, 0);
cout << ans;
return 0;
}
I 皮卡丘的梦幻之旅(middle version)
dp
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define N 1000010
#define inf 0x3f3f3f3f
#define ll long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ull unsigned long long
#define mod 1000000007
int n, m;
ll ans = 0;
int a[5001];
ll dp[5001];
int main()
{
cin >> n >> m;
for (int i = 1; i <= m; i++)
cin >> a[i];
dp[0] = 1;//相当于使每一个dp[a[i]]等于1
for (int i = 0; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (i + a[j] <= n)
//每种i加a[j]的组合方式,i有dp[i]种组合方法,a[j]只表示a[j]这一种
dp[i + a[j]] = (dp[i + a[j]] + dp[i]) % 998244353;
}
}
cout << dp[n];
return 0;
}
J 皮卡丘的梦幻之旅(hard version)
K n个数的高精度乘法
由于要取余10000,所以字符串读入,取每个字符串的后四位然后相乘就好啦
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define N 1000010
#define inf 0x3f3f3f3f
#define ll long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ull unsigned long long
#define mod 1000000007
ll n;
int main()
{
cin >> n;
ll ans = 1;
while (n--) {
string str;
cin >> str;
ll len = str.size()-1;
ll res = 0;
//len用来防止有些本来就小于四位的字符串
for (int j = len, i = 1; j >= 0 && i <= 4; i++, j--) {
int a = str[j] - '0';
res = res + a*(ll)pow(10, i - 1);
}
ans = (ans * res) % 10000;
}
cout << ans % 10000;
return 0;
}
L 轩哥的疑惑
正式赛一共14道题,年轻人不要被骗了
M 集!挡!波!
我不可能可能输,所以只有平或者赢的可能
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define N 1000010
#define inf 0x3f3f3f3f
#define ll long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ull unsigned long long
#define mod 1000000007
int n;
int main()
{
cin >> n;
string str;
cin >> str;//q代表我积攒的能量
int q = 0;
bool tr = false;
for (int i = 0; i < n; i++) {
if (str[i] == 'J') {
//等于J时,如果q不为0,就发波打死他,结束战斗,若q为0,我也集气
if (q > 0) {
tr = true;
break;
}
else q++;
}
//它挡的时候我也集气
else if (str[i] == 'D')q++;
//它发波,我就挡,挡不消耗能量
}
if (tr) cout << "win";
else cout << "draw";
return 0;
}
N 挑选未婚夫