A. Square
题意:给四个点,形成一个矩形,求这个矩形的面积
思路:没啥思路,直接模拟
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void test()
{
ll a1,b1;
ll a2,b2;
ll a3,b3,a4,b4;
cin>>a1>>b1>>a2>>b2>>a3>>b3>>a4>>b4;
ll m=max(abs(a1-a2),abs(b1-b2));
ll n=max(abs(a3-a4),abs(b3-b4));
cout<<m*n<<endl;
}
signed main()
{
ll t;
cin>>t;
while(t--)
test();
}
B. Arranging Cats
题意:给一个01字符串,可以选择三个操作,将0变为1,将1变为0,在字符串上的0和1进行交换
代码:
#include <iostream>
#include <string>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
string s, t;
cin >> s >> t;
int cnt01 = 0, cnt10 = 0;
for (int i = 0; i < n; i++) {
if (s[i] != t[i]) {
if (s[i] == '0' && t[i] == '1') {
cnt01++;
} else if (s[i] == '1' && t[i] == '0') {
cnt10++;
}
}
}
cout << max(cnt01, cnt10) << endl;
}
return 0;
}
C. Sending Messages
这个题教会了我做题要好好读题,没读懂不要急着做,我真sb
思路,。。。。,没啥思路直接模拟就行了,题一定要读明白再做
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void test() {
ll n, f, a, b, sum = 0;
cin >> n >> f >> a >> b;
vector<ll> v(n + 1);
for (int i = 1; i <= n; i++)
cin >> v[i];
sum = f;
sort(v.begin() + 1, v.end());
if (v[1] * a >= b) {
sum -= b;
} else {
sum -= v[1] * a;
}
for (int i = 2; i <= n; i++) {
if ((v[i] - v[i - 1]) * a >= b ) {
sum -= b ;
} else {
sum -= (v[i] - v[i - 1]) * a;
}
}
if (sum <= 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
signed main()
{
ll t;
cin >> t;
while(t--)
test();
return 0;
}
D. Very Different Array
无语了,比赛一个多小时做不出来,起床三分钟做出来
题意,给两个数组a,b,从b里挑选出和a一样大小的数组,然后两个数组差绝对值的和最大
思路:双指针加贪心,一个指向头,一个指向尾,根据双指针判断哪个哪个可以做出最有利的选择,然后不断做出最优解
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void test() {
ll n, m,sum1=0,sum=0;
cin >> n >> m;
ll cn=0,t1=0,t2=0;
vector<ll> A(n+1), B(m+1);
for (int i = 1; i <= n; i++)
cin >> A[i];
for (int i = 1; i <= m; i++)
cin >> B[i];
sort(A.begin()+1,A.end());
sort(B.begin()+1,B.end());
ll a1=1,am=m,i,j;
for( i=1,j=n;i<j;)
{
ll k1=max(abs(B[a1]-A[i]),abs(B[am]-A[i]));
ll k2=max(abs(B[a1]-A[j]),abs(B[am]-A[j]));
if(k2>k1)
{
if(abs(B[a1]-A[j])>abs(B[am]-A[j]))
{
sum+=abs(B[a1]-A[j]);
j--;
a1++;
}else{
sum+=abs(B[am]-A[j]);
j--;
am--;
}
}else{
if(abs(B[a1]-A[i])>abs(B[am]-A[i]))
{
sum+=abs(B[a1]-A[i]);
i++;
a1++;
}else{
sum+=abs(B[am]-A[i]);
i++;
am--;
}
}
}
if(i==j)
{
ll k1=max(abs(B[a1]-A[i]),abs(B[am]-A[i]));
ll k2=max(abs(B[a1]-A[j]),abs(B[am]-A[j]));
if(k2>k1)
{
if(abs(B[a1]-A[j])>abs(B[am]-A[j]))
{
sum+=abs(B[a1]-A[j]);
j--;
a1++;
}else{
sum+=abs(B[am]-A[j]);
j--;
am--;
}
}else{
if(abs(B[a1]-A[i])>abs(B[am]-A[i]))
{
sum+=abs(B[a1]-A[i]);
i++;
a1++;
}else{
sum+=abs(B[am]-A[i]);
i++;
am--;
}
}
}
cout<<sum<<endl;
}
signed main()
{
ll t;
cin >> t;
while(t--)
test();
return 0;
}
E. Eat the Chip
思路:
对情况进行不断分类讨论就可以,虽然代码长,情况多,但注意好各种情况就能做出来
代码:
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
using LL = long long;
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--){
int height, width, xa, ya, xb, yb;
cin >> height >> width >> xa >> ya >> xb >> yb;
if (xa >= xb){
cout << "Draw" << '\n';
continue;
}
if ((xb - xa) % 2 == 1){
if (abs(ya - yb) <= 1){
cout << "Alice" << '\n';
continue;
}
if (ya > yb){
if (ya - 1 <= (xb - xa + 1) / 2){
cout << "Alice" << '\n';
}
else{
cout << "Draw" << '\n';
}
}
else{
if (width - ya <= (xb - xa + 1) / 2){
cout << "Alice" << '\n';
}
else{
cout << "Draw" << '\n';
}
}
}
else{
if (ya == yb){
cout << "Bob" << '\n';
continue;
}
if (ya > yb){
ya = min(width, ya + 1);
xa += 1;
}
else{
ya = max(1, ya - 1);
xa += 1;
}
if (ya < yb){
if (yb - 1 <= (xb - xa + 1) / 2){
cout << "Bob" << '\n';
}
else{
cout << "Draw" << '\n';
}
}
else{
if (width - yb <= (xb - xa + 1) / 2){
cout << "Bob" << '\n';
}
else{
cout << "Draw" << '\n';
}
}
}
}
return 0;
}
浙公网安备 33010602011771号