- 伍衍 的博客
DAY2(8)
- @ 2024-8-7 19:46:25
考试错误:无。
思路:
直接判断每公里是否超速即可
代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=110;
pair<int,int> r[N],w[N];
int rr[N],ww[N];
signed main(){
freopen("speeding.in","r",stdin);
freopen("speeding.out","w",stdout);
int n,m;
cin >> n >> m;
int ans1=0,ans2=0;
for(int i=1;i<=n;i++){
cin >> r[i].first >> r[i].second;
for(int j=1;j<=r[i].first;j++){
rr[ans1+j]=r[i].second;
}
ans1+=r[i].first;
}for(int i=1;i<=m;i++){
cin >> w[i].first >> w[i].second;
for(int j=1;j<=w[i].first;j++){
ww[ans2+j]=w[i].second;
}
ans2+=w[i].first;
}
int mx=0;
for(int i=1;i<=100;i++){
if(ww[i]>rr[i]) mx=max(mx,ww[i]-rr[i]);
}
cout << mx;
}
考试错误:无。
思路:
一道模拟题,按着题目意思来就行,连思路都不用。
代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> q;
int f[10050],s[10050];
signed main(){
freopen("drink.in","r",stdin);
freopen("drink.out","w",stdout);
int n,m;
cin >> n >> m;
for(int i=1;i<=n;i++){
int x;
cin >> x;
q.push_back(x);
}
reverse(q.begin(),q.end());
int cnt=0;
while(q.size()){
int x=q.size(),y=min(m,x);
for(int i=0;i<y;i++){
s[i]=q.back();
q.pop_back();
}
for(int i=y-1;i>=0;i--){
s[i]--;
if(s[i]>0){
q.push_back(s[i]);
}
}
cnt++;
}
cout << cnt;
return 0;
}
考试错误:只判断每个僵尸离哪个加农炮近,所以只得了分。
思路:
最开始看到这题的时候没反应过来,后面才知道:这题是导弹拦截原题 !!!(代码不用我说吧,直接粘上去就可以了)
代码:
#include <bits/stdc++.h>
#define x first
#define y second
#define int long long
using namespace std;
const int N=1e5+50;
pair<int,int> a[N];
int x1,Y1,x2,y2,n;
int qq(int t){
return t*t;
}
bool cmp(pair<int,int> a,pair<int,int> b){
return qq(x1-a.x)+qq(Y1-a.y)>qq(x1-b.x)+qq(Y1-b.y);
}
int get_xs(int a,int b,int c,int d){
return qq(a-b)+qq(c-d);
}
signed main(){
freopen("pvz.in","r",stdin);
freopen("pvz.out","w",stdout);
cin >> x1 >> Y1 >> x2 >> y2 >> n;
int sc=2e9;
for(int i=1;i<=n;i++){
cin >> a[i].x >> a[i].y;
}
sort(a+1,a+n+1,cmp);
int l=0;
for(int i=1;i<=n;i++){
sc=min(sc,get_xs(x1,a[i].x,Y1,a[i].y)+l);
l=max(l,get_xs(x2,a[i].x,y2,a[i].y));
}
cout << sc;
}
考试错误:没做。
思路:因为所有最大值都会被电脑选去,所以所有次大值中的最大值就是答案。(不存在赢不了的情况)
代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[550][550];
signed main(){
freopen("sg.in","r",stdin);
freopen("sg.out","w",stdout);
int n;
cin >> n;
for(int i=1;i<=n;i++) a[i][i]=-1;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
cin >> a[i][j];
a[j][i]=a[i][j];
}
}
cout << "1\n";
for(int i=1;i<=n;i++){
sort(&a[i][1],&a[i][n+1]);
}
int mx=-1;
for(int i=1;i<=n;i++){
mx=max(mx,a[i][n-1]);
}
cout << mx;
}