丙组T1:https://www.iai.sh.cn/problem/52
#include <bits/stdc++.h>
using namespace std;
//枚举法
int main()
{
int n;
cin >> n;
int cnt = 10;
int day = 3; //星期
for(int i = 1; ; i++) //枚举天
{
cnt--; //每天消耗一个口罩
if(day == 1 || day == 2) cnt += 7; //周一周二都会新增7个口罩
if(cnt == n)
{
cout << i;
break;
}
day = (day + 1) % 7;
}
return 0;
}
丙组T2:https://www.iai.sh.cn/problem/51
#include <bits/stdc++.h>
using namespace std;
double point(char c)
{
if(c == 'A') return 4;
else if(c == 'B') return 3;
else if(c == 'C') return 2;
else if(c == 'D') return 1;
else if(c == '+') return 0.3;
else if(c == '-') return -0.3;
}
double ans;
int cnt;
int main()
{
char c;
while(cin >> c)
{
ans += point(c);
if(c >= 'A' && c <= 'D') cnt++;
}
printf("%.2f", ans / cnt);
}
丙组T3:https://www.iai.sh.cn/problem/32
#include <bits/stdc++.h>
using namespace std;
int n, m;
char c[105][105];
int dx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cin >> c[i][j];
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
int cnt = 0;
for(int k = 0; k < 8; k++)
{
int nx = i + dx[k];
int ny = j + dy[k];
if(nx < 1 || nx > n || ny < 1 || ny > m) continue;
if(c[nx][ny] == '*') cnt++;
}
if(c[i][j] == '*') cout << '*';
else cout << cnt;
}
cout << endl;
}
return 0;
}
丙组T4:https://www.iai.sh.cn/problem/31
#include <bits/stdc++.h>
using namespace std;
int s, t, ans;
int main()
{
cin >> s >> t;
//正着做不好做,因为s不一定每次都是乘2更好,有可能+1再乘2更好,比如样例2
//倒过来做,从t减1或除以2变成s
while(s < t)
{
if(t % 2 == 1) t--, ans++; //如果t是奇数,只能减1
else if(t / 2 >= s) t /= 2, ans++; //如果t/2还不小于s,就除以2
else break; //t距离s不能除以2,只能一个个减,循环减有可能会超时
}
ans += t - s; //加上最后要减1的次数
cout << ans;
return 0;
}
丙组T5:https://www.iai.sh.cn/problem/44
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
int a[N];
int maxa[N]; //maxa[i]存a[1]~a[i]的最大值
int mina[N]; //mina[i]存a[n]~a[i]的最小值
int ans;
int main()
{
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
maxa[1] = a[1];
for(int i = 2; i <= n; i++)
maxa[i] = max(maxa[i - 1], a[i]);
mina[n] = a[n];
for(int i = n - 1; i >= 1; i--)
mina[i] = min(mina[i + 1], a[i]);
for(int i = 1; i <= n; i++)
{
ans = max(ans, maxa[i] - mina[i]);
}
cout << ans;
return 0;
}
标签:月赛,cnt,return,int,上海,else,2020,ans,include From: https://www.cnblogs.com/jcwy/p/18297716