标签:open main can pre freopen 答案 ice while +=
。。。贪心从后往前枚举,合法就输出答案return掉
#include<bits/stdc++.h>
#define fi first
#define se second
#define Pit pair<int,int>
#define MP make_pair
using namespace std;
typedef long long LL;
const int N=1e5+5;
int read()
{
int x=0,p=1; char ch=getchar();
while((ch<'0' || ch>'9') && ch!='-') ch=getchar();
if(ch=='-') p=-1,ch=getchar();
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
return x*p;
}
/*-----------------------------------------------------------------*/
int a[N],b[N],g[N],k[N];
int n,X,Y;
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n=read();
for(int i=1;i<=n;i++) a[i]=read(),b[i]=read(),g[i]=read(),k[i]=read();
X=read(),Y=read();
for(int i=n;i>=1;i--)
if(X>=a[i] && X<=a[i]+g[i]-1 && Y>=b[i] && Y<=b[i]+k[i]-1)
{ printf("%d\n",i); return 0; }
return puts("-1"),0;
return 0;
}
o(n)扫一遍就好啦。。。但我想了个错的,要是我考的是这年的noip就凉凉了QAQ 可怕
#include<cstdio>
using namespace std;
int n,k,p,t,ans,price,num[110],color[200100];
int main()
{
scanf("%d%d%d",&n,&k,&p); // n个客栈 k个色调 有p块钱
for(int i=1;i<=n;i++)
{
scanf("%d%d",&color[i],&price);
if(price<=p)
{
for(int j=i;j>t;j--) num[color[j]]++;
t=i,ans+=num[color[i]]-1;
}
else ans+=num[color[i]];
}
printf("%d",ans);
return 0;
标签:open main can pre freopen 答案 ice while +=
原文地址:https://www.cnblogs.com/lzqlalala/p/11503619.html