classMinStack{//用链表模拟栈,作为栈存储的容器classListNode{int val;//当前结点的值int min;//当前最小值。用一个变量模拟最小值栈ListNode next;//下一个结点publicListNode(){}publicListNode(int val,int min,ListNode next){this.val = val;this.min = min;//min就是最小值栈this.next = next;}}ListNode head;//头结点publicMinStack(){head =newListNode();//头结点初始化}//入栈操作publicvoidpush(int val){ListNode next = head.next, cur;//获取栈顶元素next,cur是当前要插入结点if(next !=null&& next.min < val){//如果栈不为空//但是当前栈中最小值,比val更小,那么将当前结点入栈,但是最小值依然保存next.mincur =newListNode(val, next.min, next);}else{//如果栈为空,直接入栈当前结点//或者栈不为空,但是当前结点的值更小的话,那么新的最小值为当前的val值cur =newListNode(val, val, next);}head.next = cur;//头插法,实现先入后出}//出栈publicvoidpop(){ListNode del = head.next;//取出栈顶元素head.next = del.next;//头结点指向新的栈顶元素}//获取栈顶元素的值publicinttop(){return head.next.val;}//获取最小值,就在栈顶元素的min变量中保存publicintgetMin(){return head.next.min;}}/*** Your MinStack object will be instantiated and called as such:* MinStack obj = new MinStack();* obj.push(val);* obj.pop();* int param_3 = obj.top();* int param_4 = obj.getMin();*//*** Your MinStack object will be instantiated and called as such:* MinStack obj = new MinStack();* obj.push(val);* obj.pop();* int param_3 = obj.top();* int param_4 = obj.getMin();*/
文章目录 A-柠檬可乐B-左右互博C-冬眠D-守恒E-漂亮数组G-数三角形(easy) A-柠檬可乐
#include<bits/stdc.h>
#define endl \n
#define int long long
using namespace std;
int a,b,k;
void solve() {cin>>a>>b>>k;if(a>k*b…