7.28总结
7.28总结
得分情况与用时
| 题目名称 | 得分 | 用时(分钟) | 备注 |
|---|---|---|---|
| 题面看懂了,但不会写 | |||
| 打了暴力 | |||
| 总计 |
题目总结
P14357 [CSP-J 2025] 拼数(\text{number} )
题目大意
给定一个字符串,请提取里面的数字并组成一个最大数字。
解题思路
显然这是一个排序题。
我们维护一个桶t,存储每个数字出现的个数。存储完后从大到小输出即可。
正确代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int t[15];
string s;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("number.in","r",stdin);
freopen("number.out","w",stdout);
cin>>s;
//统计出现个数
for(int i=0;i<s.length();i++){
if(s[i]>='0'&&s[i]<='9')t[s[i]-'0']++;
}
//从大到小输出答案
for(int i=9;i>=0;i--){
//输出t[i]个i(当前数)
for(int j=t[i];j>=1;j--){
cout<<i;
}
}
return 0;
}
个人总结
肥肠简单的一道题,好题多出。
P1190 [NOIP 2010 普及组] 接水问题(\text{water} )
题目大意
有
解题思路
显然这是一道模拟题。
我们维护一个变量!w[i]),下一个人立刻接替位置并更新t++; w[i]=w[t];)。
当后面的所有人接替完前面人的位置后,模拟的循环结束。最后答案就是之前循环的次数加剩下的人的接水时间(max({w[1],w[2],w[3]...w[m]}))。
正确代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n,m,w[100005],ans;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("water.in","r",stdin);
freopen("water.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>w[i];
}
int t=m;//t:将要接替的人的位置
while(t<n){
//模拟每1时间的接水过程
for(int i=1;i<=m;i++){
w[i]--;//接1点水
if(!w[i]){//接完了
t++;//下一个人来
w[i]=w[t];//接替位置
}
}
ans++;//更新答案
}
//求剩下的人的接水时间
int maxw=0;
for(int i=1;i<=m;i++){
maxw=max(maxw,w[i]);
}
cout<<ans+maxw<<endl;
return 0;
}
个人总结
其实之前写过(依旧忘了),想到了要全部模拟接水的过程,就是卡在计算答案的逻辑上。最后还是写出来了。
P1056 [NOIP 2008 普及组] 排座椅(\text{seat} )
题目大意
有一个
解题思路
每条线之间是不受影响的,贡献可以单独计算。所以我们维护两个数组
正确代码
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n,m,k,l,d,x,y,p,q;
struct P{
int id,tot;//id:编号 tot:分开总数
}row[10005],col[10005];
bool cmp(P x,P y){
return x.tot>y.tot;
}
bool cmpid(P x,P y){
return x.id<y.id;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("seat.in","r",stdin);
freopen("seat.out","w",stdout);
cin>>n>>m>>k>>l>>d;
for(int i=1;i<=d;i++){
cin>>x>>y>>p>>q;
if(x!=p){//从行分开
row[min(x,p)].id=min(x,p);//记录编号
row[min(x,p)].tot++;//记录分开总数
}
else{//从行分开
col[min(y,q)].id=min(y,q);//记录编号
col[min(y,q)].tot++;//记录分开总数
}
}
//按分开的数量降序排序
sort(row+1,row+n+1,cmp);
sort(col+1,col+m+1,cmp);
//按编号升序排序
sort(row+1,row+k+1,cmpid);
sort(col+1,col+l+1,cmpid);
//输出答案
for(int i=1;i<=k;i++){
cout<<row[i].id<<" ";
}
cout<<endl;
for(int i=1;i<=l;i++){
cout<<col[i].id<<" ";
}
return 0;
}
个人总结
花了