当前位置:网站首页>2022.6.6 特长生模拟
2022.6.6 特长生模拟
2022-06-11 07:43:00 【Ayane.】
2018 2018 2018 特长生
目录:
A.密码问题
B.括号匹配问题
C.建学校问题
D.平板游戏问题
A . A. A.密码问题

分析:
构造最大最小数然后相减
CODE:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define reg register
using namespace std;
typedef long long ll;
int a[10];
int main(){
freopen("pass.in","r",stdin);
freopen("pass.out","w",stdout);
for(int i=1;i<=4;i++)
scanf("%1d",&a[i]);
sort(a+1,a+4+1);
int maxn=a[4]*1000+a[3]*100+a[2]*10+a[1];
int minn=a[1]*1000+a[2]*100+a[3]*10+a[4];
printf("%d",maxn-minn);
return 0;
}
B . B. B.括号匹配问题


分析:
先判匹配 再判是否符合规则 注意同级括号可以嵌套
CODE:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define reg register
using namespace std;
typedef long long ll;
int T;
char s[305];
int main(){
freopen("bracket.in","r",stdin);
freopen("bracket.out","w",stdout);
scanf("%d",&T);
while(T--)
{
bool ok=1;
int ld,rd,lz,rz,lx,rx;
ld=rd=lz=rz=lx=rx=0;
scanf("%s",s+1);
int len=strlen(s+1);
for(int i=1;i<=len;i++)
{
if(s[i]=='{') ld++;
if(s[i]=='}') rd++;
if(s[i]=='[') lz++;
if(s[i]==']') rz++;
if(s[i]=='(') lx++;
if(s[i]==')') rx++;
}
if((ld!=rd)||(lz!=rz)||(lx!=rx))
{
puts("NO");
continue;
}
for(int i=1;i<=len;i++)
{
if(s[i]=='{')
{
if(s[i+1]!='}')
if(s[i+1]!='['&&s[i+1]!='('&&s[i+1]!='{')
ok=0;
}
if(s[i]=='[')
{
if(s[i+1]=='{') ok=0;
if(s[i+1]!=']'&&s[i+1]!='('&&s[i+1]!='[') ok=0;
}
if(s[i]=='('&&s[i+1]!=')')
(s[i+1]=='(')?ok=1:ok=0;
}
(ok)?puts("YES"):puts("NO");
}
return 0;
}
C . C. C.建学校问题


分析:
设 f i , j f_{i,j} fi,j表示前 i i i个村庄建了 j j j个学校的最小代价 然后分别计算往前走和往后走的代价
CODE:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define reg register
using namespace std;
typedef long long ll;
const int N=105;
int n,m,w[N],dis[N][N],f[N][15],a[N][N],b[N][N],ans=0x3f3f3f3f;
int main(){
freopen("school.in","r",stdin);
freopen("school.out","w",stdout);
memset(f,0x3f,sizeof f);
memset(dis,0x3f,sizeof dis);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
dis[i][i]=0;
for(int i=1;i<=n;i++)
scanf("%d",&w[i]);
for(int i=1;i<n;i++)
{
scanf("%d",&dis[i][i+1]);
dis[i+1][i]=dis[i][i+1];
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
a[i][j]=a[i][j-1]+dis[j][i]*w[j];
for(int i=1;i<=n;i++)
for(int j=i;j>=1;j--)
b[j][i]=b[j+1][i]+dis[j][i]*w[j];
for(int i=1;i<=n;i++)
{
f[i][1]=b[1][i];
for(int j=1;j<=m;j++)
for(int k=j-1;k<=i;k++)
for(int l=k+1;l<=i;l++)
f[i][j]=min(f[i][j],f[k][j-1]+a[k][l-1]+b[l][i]);
}
for(int i=m;i<=n;i++)
ans=min(ans,f[i][m]+a[i][n]);
printf("%d",ans);
return 0;
}
D . D. D.平板游戏问题


分析:
分类讨论 注意柱子的距离是 0.5 0.5 0.5 全部先 × 2 ×2 ×2
CODE:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define reg register
using namespace std;
typedef long long ll;
int n;
ll ans;
struct plat{
int y,x1,x2;
}a[105];
bool cmp(plat a,plat b){
return a.y<b.y;}
bool checkin(int x,int L,int R){
return (x<=R)&&(x>=L);}
int main(){
freopen("platforme.in","r",stdin);
freopen("platforme.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d%d",&a[i].y,&a[i].x1,&a[i].x2);
a[i].x1<<=1;
a[i].x2<<=1;
}
sort(a+1,a+n+1,cmp);
ans=(a[1].y<<1);
for(int i=2;i<=n;i++)
{
bool f=0,fl=0,fr=0;
if((a[i].x2-1>a[i-1].x2&&a[i].x1+1<a[i-1].x1)||(a[i].x2-1<=a[i-1].x1)||(a[i].x1+1>=a[i-1].x2))
{
for(int j=i-2;j>=1;j--)
if(checkin(a[i].x1+1,a[j].x1,a[j].x2))
{
ans+=(a[i].y-a[j].y);
fl=1;
break;
}
for(int j=i-2;j>=1;j--)
if(checkin(a[i].x2-1,a[j].x1,a[j].x2))
{
ans+=(a[i].y-a[j].y);
fr=1;
break;
}
if(!fl&&fr) ans+=a[i].y;
if(fl&&!fr) ans+=a[i].y;
if(!fl&&!fr) ans+=(a[i].y<<1);
}
else if(checkin(a[i].x1+1,a[i-1].x1,a[i-1].x2)&&checkin(a[i].x2-1,a[i-1].x1,a[i-1].x2)) ans+=((a[i].y-a[i-1].y)<<1);
else if(checkin(a[i].x1+1,a[i-1].x1,a[i-1].x2)&&!checkin(a[i].x2-1,a[i-1].x1,a[i-1].x2))
{
ans+=(a[i].y-a[i-1].y);
for(int j=i-2;j>=1;j--)
if(checkin(a[i].x2-1,a[j].x1,a[j].x2))
{
ans+=(a[i].y-a[j].y);
f=1;
break;
}
if(!f) ans+=a[i].y;
}
else if(checkin(a[i].x2-1,a[i-1].x1,a[i-1].x2)&&!checkin(a[i].x1+1,a[i-1].x1,a[i-1].x2))
{
ans+=(a[i].y-a[i-1].y);
for(int j=i-2;j>=1;j--)
if(checkin(a[i].x1+1,a[j].x1,a[j].x2))
{
ans+=(a[i].y-a[j].y);
f=1;
break;
}
if(!f) ans+=a[i].y;
}
}
printf("%lld",ans);
return 0;
}
边栏推荐
- 零基础自学SQL课程 | UNION 联合查询
- 【AtCoder1980】Mysterious Light(数学模拟)
- 测试4年裸辞失业,面试15k的测试岗被按在地上摩擦,结局让我崩溃大哭...
- Uoj 553 [unr 4] caproic acid set [computational geometry (points in circle → points in half plane)]
- 2020080 simulation competition [horizontal and vertical coordinates do not affect each other, cactus minimum cut, combined meaning translation formula]
- Nosqlzoo question brushing-1
- Zero foundation self-study SQL course | union joint query
- Modular linear equations (Chinese remainder theorem + general solution)
- 黑群晖DSM7.0.1物理机安装教程
- 零基础自学SQL课程 | OUTER JOIN外连接
猜你喜欢

零基础自学SQL课程 | UNION 联合查询

测试4年裸辞失业,面试15k的测试岗被按在地上摩擦,结局让我崩溃大哭...
![2020080 simulation competition [horizontal and vertical coordinates do not affect each other, cactus minimum cut, combined meaning translation formula]](/img/4d/a67a63d2c4eb80c98315c3057b01b9.jpg)
2020080 simulation competition [horizontal and vertical coordinates do not affect each other, cactus minimum cut, combined meaning translation formula]

二本毕业,银行外包测试工作 4 个月有余。聊聊一些真实感受 ...

Aiop introduction

How to prepare for the new PMP syllabus exam?

C memory alignment

【AtCoder2306】Rearranging(拓扑)

Deux diplômés, la Banque a externalisé le travail d'essai pendant plus de quatre mois. Parler de vrais sentiments...

Zero foundation self-study SQL course | union joint query
随机推荐
[noip2016 d1t3] changing classrooms (expectation dp+floyd) (trap of extreme thinking!)
You got 8K in the 3-year function test, but you were actually pretending to work hard
Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]
Switch statement
[atcoder2000] leftmost ball (dp+ combination number)
Configuration software -- control drag and drop
【NOIP2016 D1T3】换教室(期望DP+Floyd)(究极思维陷阱!)
.NET C#基础(6):命名空间 - 有名字的作用域
C language volatile
【AtCoder2306】Rearranging(拓扑)
A correction book full of sad tears
Wc2020 course selection
[IOT] project management: how to build a better cross functional team?
Implementation of stack (C language)
Long dialogue in June 2017
黑群晖DSM7.0.1物理机安装教程
C language - Growth Diary -03- function definition and function prototype declaration
Sdl-4 PCM playback
Import on CSDN MD file
MFC custom string linked list