A.
根据正方形4个角的特性,可以把它们排序处理,
得到长和高,相乘得面积
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
bool cmp(pair<int,int>x,pair<int,int>y){
if(x.first==y.first)return x.second<y.second;
else return x.first<y.first;
}
void solve(){ vector<pair<int,int>>a(5);
for(int i=1;i<=4;i++){
cin>>a[i].first>>a[i].second;
}
sort(a.begin()+1,a.end(),cmp);
int h=a[2].second-a[1].second,w=a[3].first-a[1].first;
cout<<h*w<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
cin>>hey_left;
while(hey_left--){
solve();
}
}
B.
以期望字符串为基准,对比原字符串,对于每个位置,记录多出的猫和少的猫,答案为两者之差+两者较小的值
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
void solve(){
int n;cin>>n;
string t,s;cin>>t>>s;
int much=0,less=0;
for(int i=0;i<n;i++){
if(t[i]=='0'&&s[i]=='1')less++;
else if(t[i]=='1'&&s[i]=='0')much++;
}
int res=abs(much-less)+min(much,less);
cout<<res<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
cin>>hey_left;
while(hey_left--){
solve();
}
}
C.
贪心,在时间差内比较两种方式哪一种耗电更少
注意电量为0不能发消息,同一时刻也不行
同一时刻的概念看样例
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+10;
void solve(){
int n,f,a,b;cin>>n>>f>>a>>b;
vector<int>time(n+1);
int tmp=0;
for(int i=1;i<=n;i++){
cin>>time[i];
int t1 = a * (time[i] - time[i - 1]);
int t2 = b;
tmp+=min(t1,t2);
}
if(tmp<f)cout<<"YES\n";
else cout<<"NO\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int hey_left=1;
cin>>hey_left;
while(hey_left--){
solve();
}
}
标签:int,18,Codeforces,long,hey,solve,first,left
From: https://www.cnblogs.com/wwww-/p/17991348