A
写的比较傻
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define mst(a, b) memset(a, b, sizeof a)
#define REP(i, x, n) for(int i = x; i <= n; ++i)
const int qq = 2e5 + 10;
int num[105][105];
int a[105], b[105];
int n;
bool Check(int x, int y){
int cnt1 = 0;
for(int i = 1; i <= n; ++i)
if(i != y) a[cnt1++] = num[x][i];
int cnt2 = 0;
for(int i = 1; i <= n; ++i)
if(i != x) b[cnt2++] = num[i][y];
for(int i = 0; i < cnt1; ++i)
for(int j = 0; j < cnt2; ++j)
if(a[i] + b[j] == num[x][y]) return true;
return false;
}
int main(){
scanf("%d", &n);
REP(i, 1, n)
REP(j, 1, n)
scanf("%d", &num[i][j]);
bool f = true;
REP(i, 1, n){
REP(j, 1, n){
if(num[i][j] != 1){
if(!Check(i, j)) f = false;
}
}
}
if(f) puts("Yes");
else puts("No");
return 0;
}
B
题意:给出一条直线,选出一个矩形,要求矩形内的整数点x,y的和最大
思路:枚举y轴,二分找最大的x
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define mst(a, b) memset(a, b, sizeof a)
#define REP(i, x, n) for(int i = x; i <= n; ++i)
const int qq = 2e5 + 10;
LL m, b;
bool Check(LL x, LL y){
double f = x * 1.0 / m;
f = y * 1.0 + f - b * 1.0;
if(f > 0) return false;
return true;
}
LL Cal(LL y){
LL l = 0, r = m * b, mid;
LL x = 0;
while(l <= r){
mid = (l + r) / 2;
if(Check(mid, y)){
x = mid;
l = mid + 1;
}else{
r = mid - 1;
}
}
// printf("%lld %lld\n", x, y);
LL xx = y + 1, yy = x + 1;
LL ans = ((1LL + x) * x / 2LL) * xx + ((1LL + y) * y / 2LL) * yy;
return ans;
}
int main(){
scanf("%lld%lld", &m, &b);
LL maxn = 0;
for(int i = 0; i <= b; ++i){
maxn = max(maxn, Cal(i));
}
printf("%lld\n", maxn);
return 0;
}
C
题意:有一个栈,可以放元素进去,也可以消除栈顶元素,但是要按元素1到元素n的顺序消除,每次可以对栈内的元素排序,问最少排多少次。
思路:分两个堆,一堆是已经排好的,一堆是没排好的进行讨论即可
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define mst(a, b) memset(a, b, sizeof a)
#define REP(i, x, n) for(int i = x; i <= n; ++i)
const int qq = 2e5 + 10;
int n;
map<int, int> mp1, mp2;
int main(){
scanf("%d", &n);
n = 2 * n - 1;
int x = 1, top = 0;
bool f = true;
char op[10];
int ans = 0, num;
map<int, int>::iterator it;
while(n--){
scanf("%s%d", op, &num);
if(op[0] == 'a'){
mp2[num] = ++top;
continue;
}
if(mp2.size() == 0){
mp1.erase(mp1.begin());
x++;
}else{
if(mp2[x] == top){
mp2.erase(mp2.find(x));
top--;
x++;
}else{
ans++;
for(it = mp2.begin(); it != mp2.end(); ++it){
mp1[it->first] = it->second;
}
mp2.clear();
mp1.erase(mp1.begin());
x++;
}
}
}
printf("%d\n", ans);
return 0;
}