8.22训练课
xiezirui1104 · · 个人记录
未完成的无错因
| 题目 | 分数 |
|---|---|
| T1 | 未完成 |
| T2 | 未完成 |
| T3 | 未完成 |
| T4 | 100 |
| T5 | 100 |
| T6 | 未完成 |
| T7 | 30 |
T1 [CCC 2025 Senior] 挂画 / Positioning Peter's Paintings
无思路
题意:
有两幅画,一幅画的长为
这两幅画必须全部在画框中;
这两幅画不能重叠(但是允许边缘触碰);
这两幅画不能旋转;
这两幅画边缘必须与地面平行,或者垂直于地面。
思路:
两幅画要摆放进画框里,要么是一个在上,一个在下;要么是一个在左,一个在右,如果是求周长的话:左右结构的就是:宽相加+两个长里长的那一个;上下结构的就是:长相加+两个宽里长的宽
错误代码:
无
正确代码:
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a,b,x,y;
cin >> a >> b >> x >> y;
int s1 = (b+y) + max(a,x);//上下结构
int s2 = (a+x) + max(b,y);//左右结构
cout << min(s1,s2) * 2;
return 0;
}
T2 [语言月赛202208] 俊俏地鼠的远亲
无思路
题意:
给出一个
对于每个位置,求亲戚的最远距离
思路:
我们可以枚举位置
错误代码:
无
正确代码:
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int s[55][55];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin >> n >> m;
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= m ; j++){
cin >> s[i][j];
}
}
//枚举现在位置
for(int i = 1 ; i <= n ; i++){
for(int j = 1 ; j <= m ; j++){
int maxx = 0;
//枚举其他人的位置
for(int a = 1 ; a <= n ; a++){
for(int b = 1 ; b <= m ; b++){
if(s[i][j] == s[a][b]){//只要满足条件
maxx = max(maxx,(i - a) * (i - a) + (b - j) * (b - j));
}
}
}
cout << maxx << " ";
}
cout << "\n";
}
return 0;
}
T3 尼古拉斯的画框
无思路
题意:
有
思路:
这里需要统计每个长度的木棍出现了多少次,再拼成画框,所以统计出现次数要么用桶,要么用
错误代码:
无
正确代码:
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e6 + 5;
int tong[N];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for(int i = 1 ; i <= n ; i++){
int x;
cin >> x;
tong[x]++;
}
int ans = 0;
for(int i = 1 ; i <= 1e6 ; i++){//遍历桶
ans += tong[i]/2;//两个为一组
}
cout << ans / 2;//最后四个为一组,但是前面除了2
return 0;
}
T6 [蓝桥杯 2016 国 C] 赢球票
无思路
题意:
给出
样例1
我找的
思路:
可以先用一个队列存进去,接着把队列转换为环形,去遍历看最后能拿都多少彩票?
可以在遍历里先增加报数,再看报的数是否跟卡牌的数一样
错误代码:
无
正确代码:
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
queue<int>q;
int n;
int f(queue<int>q){
int dq = 0;//当前报数的数字
int s = 0;//拿走得票数
while(q.size() != 0 && dq <= n){
dq++;
if(dq == q.front()){
s += q.front();
q.pop();
dq = 0;
}else{
q.push(q.front());
q.pop();
}
}
return s;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1 ;i <= n ; i++){
int x;
cin >> x;
q.push(x);
}
int maxx = 0;
for(int i = 1 ; i <= n ; i++){
maxx = max(maxx,f(q));//最大值
q.push(q.front());//成环
q.pop();
}
cout << maxx;
return 0;
}
T7 [NOIP 2010 提高组] 机器翻译
有思路
题意:
题目讲的是有一个内存为
思路:
先把单词都从队尾存入,存一个标记一下,计数器加一,如果满了,就从对头清除,标记清除,再把单词从队尾加入
错误代码:
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
queue<int>q;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int m,n;
cin >> m >> n;
int cx = 0;
for(int i = 1 ; i <= n ; i++){
int x,f = 1;
cin >> x;
if(q.size() > m){
q.pop();
}
for(int i = 1 ; i <= q.size() ; i++){
if(q.front() == x){
f = 0;
}else{
q.push(q.front());
q.pop();
}
}
if(f == 1){
q.push(x);
cx++;
}
}
cout << cx;
return 0;
}
正确代码:
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
queue<int>q;
int tong[1005];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int m,n;
cin >> m >> n;
int cx = 0;
for(int i = 1 ; i <= n ; i++){
int x;
cin >> x;
if(tong[x] == 0){//没有出现过
if(q.size() >= m){//内存不够
tong[q.front()] = 0;
q.pop();
}
q.push(x);
tong[x] = 1;//记录
cx++;
}
}
cout << cx;
return 0;
}
错因:
没有用桶标记
感谢观看