当前位置: 首页 > java >正文

Y1代码AC集

括号匹配

#include<bits/stdc++.h>
using namespace std;
char st[1100];
string s;
int top;
int main(){cin>>s;int len=s.size();for(int i=0;i<len;i++){if(s[i]=='['||s[i]=='('){st[++top]=s[i];    }else{if(top==0){cout<<"Wrong";return 0;}if(s[i]==']'){if(st[top]=='['){top--;}} if(s[i]==')'){if(st[top]=='('){top--;}}}}if(top==0){cout<<"OK";}else{cout<<"Wrong";}return 0;
}

操作系统

#include<bits/stdc++.h>
using namespace std;
struct node{int num,gtim,timed,you;friend bool operator<(node a,node b){//重载运算符< (priority是反着的(即符合要求的往后放))if(a.you!=b.you){return a.you<b.you;}else{return a.gtim>b.gtim;}}
};
long long ans;
int n,g,t,y,now;
priority_queue<node>q; 
int main(){//小顶堆内放的是可以进行买入的操作的金额while(cin>>n>>g>>t>>y){//还有新任务到达while(!q.empty()&&now+q.top().timed<=g){now+=q.top().timed;//省略了完成任务的时间cout<<q.top().num<<" "<<now<<"\n";q.pop();}if(!q.empty()){//时间不够node x=q.top();//返回值不是引用,只能先取队头,改完再放进去(维护队列有序)q.pop();x.timed-=g-now;//先处理一部分,时间消耗为下一个任务到达时间-当前时间,所需时间减少q.push(x);}now=g;//看作瞬间把这部分任务处理完,所花费的时间立刻减去(即新任务立刻到达)q.push({n,g,t,y});//放进去后再进入下个循环}while(!q.empty()){//没有新任务到达now+=q.top().timed;cout<<q.top().num<<" "<<now<<"\n";q.pop();}return 0;
} 

序列 

#include<bits/stdc++.h>
using namespace std;
int gcnt[51000],fcnt[51000],a[51000],f[51000],g[51000],sum[51000];
long long ans;
int n;
int t;
int lowbit(int t){//树状数组return t&-t;
}
void updata(int cnt[],int x,int y){for(int i=x;i<=n;i+=lowbit(i)){cnt[i]+=y;}
}
int getsum(int cnt[],int x){int ff=0;for(int i=x;i>=1;i-=lowbit(i)){ff+=cnt[i];}return (long long)ff;
}
int main(){scanf("%d",&t);while(t--){memset(gcnt,0,sizeof gcnt);memset(fcnt,0,sizeof fcnt);ans=0;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);}for(int i=1;i<=n;i++){f[i]=getsum(fcnt,a[i]);updata(fcnt,a[i],1);}for(int i=1;i<=n;i++){sum[i]=sum[i-1]+f[i];//前缀和}for(int i=n;i>=1;i--){g[i]=getsum(gcnt,n)-getsum(gcnt,a[i]);// cout<<getsum(a[i])<<"\n";updata(gcnt,a[i],1);}// for(int i=1;i<=n;i++){//  cout<<f[i]<<" "<<g[i]<<"\n";//}for(int i=1;i<=n;i++){ans+=(long long)g[i]*sum[i-1];//防止溢出}printf("%lld\n",ans);}return 0;
}

http://www.xdnf.cn/news/3418.html

相关文章:

  • 坚鹏:平安保险集团《保险行业发展趋势与AI应用方法及案例》培训
  • 【Redis】Another Redis Desktop Manager 安装指南
  • 深入理解虚拟机与容器:原理、对比与应用场景分析
  • 动态规划简单题2
  • 算法-堆、排序算法、矩阵乘法
  • 面试手撕——迭代法中序遍历二叉树
  • 负载均衡深度实践:基于Nginx+Keepalived的高可用方案与Zabbix监控设计
  • Cesium Entity动态更新
  • 嵌入式AI还是一片蓝海
  • Day107 | 147.对链表进行插入排序 | 简单选择、冒泡、直接插入
  • 【专题五】位运算(2)
  • AXI中的out of order和interleaving的定义和两者的差别?
  • OSPF的路由
  • Go-web开发之社区功能
  • Java 中那些奇怪的空指针报错场景及解决方案NullPointerException
  • 【计算机视觉】语义分割:MMSegmentation:OpenMMLab开源语义分割框架实战指南
  • MySQL数据同步之Canal讲解
  • 2025年- H16-Lc124-169.多数元素(技巧)---java版
  • 7.0/Q1,GBD数据库最新文章解读
  • ClackyAI:下一代智能云开发环境的技术革新与实践价值
  • WPF使用依赖注入框架AutoMapper
  • 仿腾讯会议——服务器结构讲解
  • Matlab/Simulink - BLDC直流无刷电机仿真基础教程(四) - PWM调制模拟
  • 后端工程师需要掌握哪些基础技能
  • 机器人--底盘
  • 人才答辩ppt优化技巧_杰青_优青_万人计划青年拔尖人才_青年长江学者ppt制作案例
  • 2025五一杯A题五一杯数学建模思路代码文章教学:支路车流量推测问题
  • 部署.NET6.0 Web API项目到Docker
  • 实现了一个基于寄存器操作STM32F103C8t6的工程, 并实现对PA1,PA2接LED正极的点灯操作
  • npm宿主依赖、宿主环境依赖(peerDependencies)(指由宿主环境提供的依赖)