已完结
比赛链接
A题:溜圈圈
1.2019 CCPC Final L题
2.题解在另一篇上面,这波是套娃
B题:Thursday out
1.补充了wjq大佬的upper_bound做法
2.补充了燕大学长的尺标法
C题:爱做笔记的Awen
1.string类
2.erase函数
D题:Awen的一卡通
1.g数组存的是地图,d数组存的是步数
2.d = -1表示这个点没被走过
3.memset只能0和-1
E题:Iris天下第一
1.直接dp超时,m和n太大
2.所以先贪心再背包
F题:我的梦想是世界和平!
1.把a和c较大的那个等分了,把b拿出来
2.暴力是对于每个b,往三个台里最小的那个填
3.最后输出三个台最大的
4.这个过程可以直接贪心
G题:跳格子
1.最长连续下降子序列
2.注意从1开始,以免访问a[-1]
H题:计分板
1.与其对N-1个减1
2.倒不如对1个加1
3.比较的时候+k-q就完事
//A.溜圈圈:点一,线二,面周长
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t --)
{
int m, n;
cin >> m >> n;
if (m >= n) swap(m, n);
if (m == 1 && n == 1) cout << 1;
else if (m == 1 && n > 1) cout << 2;
else if (m > 1 && n > 1) cout << 2 * (m + n - 2);
cout << endl;
}
return 0;
}
// B.Thursday out:前缀和,二分,尺标法
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1000000007;
int q[maxn], sum[maxn];
signed main()
{
int T;
cin >> T;
while (T --)
{
int n, x;
cin >> n >> x;
for (int i = 1; i <= n; i ++)
{
cin >> q[i];
sum[i] = sum[i - 1] + q[i];
}
int ans = 0,l = 1, r = n;
for (int i = 1; i <= n; i ++)
{
if (sum[r] - sum[i - 1] < x) break;
while (l < r)
{
int mid = l + r >> 1;
if (sum[mid] - sum[i - 1] < x) l = mid + 1;
else r = mid;
}
ans += n - r + 1;
ans %= mod;
r = n;
}
cout << ans << endl;
}
return 0;
}
// B.Thursday out:前缀和,upper_bound
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
const int maxn = 1e5 + 5;
int food[maxn], sum[maxn];
int T, n, x;
int main()
{
cin >> T;
while (T --)
{
cin >> n >> x;
for (int i = 1; i <= n; i ++)
{
cin >> food[i];
sum[i] = sum[i - 1] + food[i];
}
int ans = 0;
for (int i = 1; i <= n; i ++)
{
if(sum[i] < x) continue;
int temp = upper_bound (sum + 1, sum + i, sum[i] - x) - sum - 1;
ans += temp + 1;
ans %= mod;
}
cout << ans << endl;
}
return 0;
}
//C:爱做笔记的Awen:string天下无敌!
#include <bits/stdc++.h>
using namespace std;
int n, cnt;
string ans, choose, add, temp;
int main()
{
cin >> n;
while (n --)
{
cin >> choose;
if (choose == "Add")
{
cin >> cnt >> add;
ans += add;
}
if (choose == "Copy")
{
temp = ans;
}
if (choose == "Del")
{
cin >> cnt;
ans.erase(ans.size() - cnt);
}
if (choose == "Paste")
{
ans += temp;
}
}
cout << ans << endl;
return 0;
}
//D:Awen的一卡通:BFS
#include <bits/stdc++.h>
#define PII pair<int, int>
using namespace std;
int n, m, a;
const int maxn = 105;
char g[maxn][maxn];
int d[maxn][maxn];
int begin_x, begin_y;
int ans_x, ans_z;
void bfs()
{
queue<PII> q;
q.push({begin_x, begin_y});
memset(d, -1, sizeof d);
d[begin_x][begin_y] = 0;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
while (q.size())
{
auto t = q.front();
q.pop();
for (int i = 0; i < 4; i ++)
{
int x = t.first + dx[i];
int y = t.second + dy[i];
if (x >= 0 && x < n && y >= 0 && y < m && g[x][y] != '*' && d[x][y] == -1)
{
d[x][y] = d[t.first][t.second] + 1;
q.push({x, y});
}
}
}
return;
}
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i ++)
{
for (int j = 0; j < m; j ++)
{
cin >> g[i][j];
if(g[i][j] == 's')
{
begin_x = i;
begin_y = j;
}
}
}
cin >> a;
bfs();
for (int i = 0; i < n; i ++)
{
for (int j = 0; j < m; j ++)
{
if (g[i][j] == 'x') ans_x = d[i][j] * 2 + a;
if (g[i][j] == 'z') ans_z = d[i][j] * 2;
}
}
if (ans_x == ans_z) cout << "awennb";
else if (ans_x < ans_z) cout << "ying ying ying";
else cout << "wo tu le";
cout << endl;
return 0;
}
//E.Iris天下第一:贪心,dp背包,琛爹天下第一!
#include <bits/stdc++.h>
#define maxn 300005
#define int long long
using namespace std;
int n , m , ans;
struct volume_value
{
int volume;
int value;
};
bool cmp(volume_value x , volume_value y)
{
return x.value * y.volume < y.value * x.volume ;
}
int dp[maxn];
volume_value boy[maxn];
signed main()
{
cin >> n >> m;
for(int i = 1 ; i <= n ; ++i)
{
cin >> boy[i].volume >> boy[i].value;
}
sort(boy + 1, boy + 1 + n , cmp);
while(m > 6 && n)
{
m -= boy[n].volume;
ans += boy[n].value;
n -- ;
}
for(int i = 1; i <= n ; i ++)
{
for(int j = m; j >= boy[i].volume ;j--)
{
dp[j] = max(dp[j] , dp[j - boy[i].volume] + boy[i].value) ;
}
}
int Max = 0 ;
for(int i = 0 ; i <= m ; ++i)
{
Max = max(Max , dp[i]) ;
}
cout << Max + ans << endl ;
}
//F.我的梦想是世界和平:贪心
#include <bits/stdc++.h>
using namespace std;
int t;
int a, b, c;
int a_room[3];
int main()
{
cin >> t;
while (t --)
{
cin >> a >> b >> c;
if (c < a) swap(a, c);
a_room[0] = c/2;
a_room[1] = c - c/2;
a_room[2] = a;
sort(a_room, a_room + 3);
if (a_room[2] * 3 < a + b + c)
{
double a1 = a, b1 = b, c1 = c;
cout << ceil((a1 + b1 + c1) / 3);
}
else
{
cout << a_room[2];
}
cout << endl;
}
return 0;
}
//G.跳格子:dp最长连续下降子序列
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
int a_steps[maxn], dp[maxn];
int n, ans;
int main()
{
cin >> n;
for(int i = 0; i < n; i ++)
{
cin >> a_steps[i];
}
for(int i = 1; i < n; i ++)
{
if(a_steps[i - 1] > a_steps[i] )
{
dp[i] = dp[i - 1] + 1;
}
}
for(int i = 0; i < n; i ++)
{
ans = max(ans, dp[i]);
}
cout << ans;
return 0;
}
//H.计分板:直接--好像会超时,改成++
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 300000 + 5;
ll a[maxn];
int main()
{
ll n, k, q;
cin >> n >> k >> q;
for (ll i = 1; i <= q; i ++)
{
ll x;
cin >> x;
a[x] ++;
}
for (ll i = 1; i <= n; i ++)
{
if (a[i] + k - q> 0) cout << "Yes" << ' ';
else cout << "No" << ' ';
}
return 0;
}