60 条题解
-
5熊.豪 LV 7 @ 2017-03-10 20:09:37
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>using namespace std;
int main()
{
int n,x,y,ans=-1;
int a[100005],b[100005],g[100005],k[100005];
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i]>>g[i]>>k[i];
}
cin>>x>>y;
for(int j=1;j<=n;j++)
{
if(x>=a[j]&&x<=a[j]+g[j]&&y>=b[j]&&y<=b[j]+k[j])
{
ans=j;
}
}
cout<<ans;
return 0;
} -
22017-11-01 15:50:04@
好水的题啊啊啊啊啊啊啊啊啊
一开始还以为很难
然后发现n这么小随随便便就过了
```cpp
#include<bits/stdc++.h>
using namespace std;
int n;
int a[1000000][4];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i][0]>>a[i][1]>>a[i][2]>>a[i][3];
int t1,t2;
cin>>t1>>t2;
for(int i=n;i>=1;i--)if(t1>=a[i][0]&&t1<=a[i][0]+a[i][2]&&t2>=a[i][1]&&t2<=a[i][1]+a[i][3])
{
cout<<i;
return 0;
}
cout<<-1;
return 0;}
``` -
12021-09-04 14:04:31@
#include<cstdio> #include<iostream> using namespace std; int main() { int i,a[10001][4],n,x,y,f=-1; cin>>n; for( i=1; i<=n; i++){ cin>>a[i][0]>>a[i][1]>>a[i][2]>>a[i][3]; a[i][2]+=a[i][0]; a[i][3]+=a[i][1]; } cin>>x>>y; for(i=n;i>=1;i--){ if(a[i][0]<=x && a[i][1]<=y && a[i][2]>=x && a[i][3]>=y){ cout<<i; f=1; break; } } if(f==-1) cout<<f; return 0; }
-
12018-12-16 19:07:45@
Accepted
状态 耗时 内存占用
#1 Accepted 1ms 448.0 KiB
#2 Accepted 1ms 448.0 KiB
#3 Accepted 1ms 448.0 KiB
#4 Accepted 1ms 448.0 KiB
#5 Accepted 1ms 448.0 KiB
#6 Accepted 1ms 448.0 KiB
#7 Accepted 3ms 448.0 KiB
#8 Accepted 4ms 448.0 KiB
#9 Accepted 7ms 448.0 KiB
#10 Accepted 4ms 448.0 KiB#include<iostream> #include<algorithm> using namespace std; //呵了个呵 //大神万岁 //分割线--------------------------------------------------$ //结构定义区 struct ditan{ int a,b,g,k; ditan() { a=b=g=k=0; } }; //全局变量区 ditan dt[10001]; int n,x,y,ans=-1; //函数声明区 //主函数开始! int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=1;i<=n;i++) { cin>>dt[i].a>>dt[i].b>>dt[i].g>>dt[i].k; } cin>>x>>y; for(int i=1;i<=n;i++) { if(x>=dt[i].a && y>=dt[i].b && x<=dt[i].a+dt[i].g && y<=dt[i].b+dt[i].k) ans=i; } cout<<ans; return 0; } //函数实现区
-
12018-02-06 10:05:39@
#include<cstdio> struct carpet{ int num; int a; int b; int g; int k; }ca[10010]; int ans=-1; int main(){ int n, x, y; scanf("%d", &n); for(int i=1; i<=n; i++) scanf("%d%d%d%d", &ca[i].a, &ca[i].b, &ca[i].g, &ca[i].k); scanf("%d%d", &x, &y); for(int i=1; i<=n; i++){ int _x=ca[i].a+ca[i].g; int _y=ca[i].b+ca[i].k; if(x<=_x&&x>=ca[i].a&&y<=_y&&y>=ca[i].b) ans=i; } printf("%d", ans); return 0; }
-
02022-08-30 09:58:17@
#include<bits/stdc++.h> using namespace std; int main() { int n,x,y; int a[10001],b[10001],g[10001],k[10001]; int i; cin>>n; for(i=1;i<=n;i++) { cin>>a[i]>>b[i]; cin>>g[i]>>k[i]; } cin>>x>>y; for(i=n;i>=1;i--) { if((x>=a[i]&&x<=a[i]+g[i]) && (y>=b[i]&&y<=b[i]+k[i])) { cout<<i<<endl; return 0; } } cout<<-1<<endl; return 0; }
-
02022-08-30 09:57:55@
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,x,y;
int a[10001],b[10001],g[10001],k[10001];
int i;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
cin>>g[i]>>k[i];
}
cin>>x>>y;
for(i=n;i>=1;i--)
{
if((x>=a[i]&&x<=a[i]+g[i]) && (y>=b[i]&&y<=b[i]+k[i]))
{
cout<<i<<endl;
return 0;
}
}
cout<<-1<<endl;
return 0;
} -
02020-04-06 14:39:23@
#include <iostream> //[2011提高组Day1-A]铺地毯 #include <algorithm> using namespace std; const int MAXN = 10002; struct Node{ int a, b; int g, k; } F[MAXN]; bool Ar(int x, int y, int i) { if(x >= F[i].a && x <= F[i].a + F[i].g) if(y >= F[i].b && y <= F[i].b + F[i].k) return true; return false; } int main() { int n, a, b, g, k, x, y; cin >> n; for (int i = 1; i <= n; i++) cin >> F[i].a >> F[i].b >> F[i].g >> F[i].k; cin >> x >> y; int ans; for (ans = n; ans > 0; ans--) if(Ar(x, y, ans)) break; if(ans) cout << ans << endl; else cout << -1 << endl; system("pause"); return 0; }
-
02018-07-25 15:08:01@
因为这里的n有点小(貌似正常是100000?)所以开个二维应该(?)可以……
代码是空间多时间短,如果要空间少的话可以拿一个地毯判一个
#include<iostream>
#include<cstdio>using namespace std;
#define l long
const l N=100010;
l n;
l a[N],b[N],g[N],k[N];
l x,y;l read()
{
l d=0,f=1;
char c=getchar();
while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0' && c<='9'){d=d*10+c-'0';c=getchar();}
return d*f;
}int main()
{
//freopen("carpet.in","r",stdin);
//freopen("carpet.out","w",stdout);
n=read();
for(l i=1;i<=n;i++){a[i]=read();b[i]=read();g[i]=read();k[i]=read();}
x=read();y=read();for(l i=n;i>=1;i--)
if(x>=a[i] && x<=a[i]+g[i] && y>=b[i] && y<=b[i]+k[i])
{printf("%ld\n",i);return 0;}printf("-1\n");return 0;
} -
02018-05-16 16:33:30@
#include <iostream> using namespace std; int main() { int n; cin>>n; int a[4][n],i; for(i=0;i<n;i++) cin>>a[0][i]>>a[1][i]>>a[2][i]>>a[3][i]; int x,y; cin>>x>>y; int total=0; for(i=0;i<n;i++) if(a[0][i]<=x&&a[1][i]<=y&&a[0][i]+a[2][i]>=x&&a[1][i]+a[3][i]>=y) total=i+1; if(total>0) cout<<total<<endl; else if(total==0) cout<<"-1"<<endl; return 0; }
-
02017-10-15 14:24:17@
......
#include <iostream> using namespace std; #define For(aHJEfaks, fwbjkWK, AENGIBv) for (int aHJEfaks = fwbjkWK; aHJEfaks <= AENGIBv; ++aHJEfaks) #define For2(aHJEfaks, fwbjkWK, AENGIBv) for (auto aHJEfaks = fwbjkWK; aHJEfaks != AENGIBv; ++aHJEfaks) int n; int x[20000], y[20000], lx[20000], ly[20000]; int main(){ cin >> n; For(i, 1, n){ cin >> x[i] >> y[i] >> lx[i] >> ly[i]; } int x0, y0; cin >> x0 >> y0; for (int j = n; j > 0; --j) { if (x[j] <= x0 && x0 <= x[j] + lx[j] && y[j] <= y0 && y0 <= y[j] + ly[j]){ cout << j << endl; return 0; } } cout << -1 << endl; return 0; }
-
02017-10-10 23:30:00@
开二维爆炸orz...
#include<iostream> const int maxn=10005; int a[maxn],b[maxn],g[maxn],k[maxn]; using namespace std; int main() { int n,x,y,ans=-1;//-1方便输出 cin>>n; for (int i=1;i<=n;i++) cin>>a[i]>>b[i]>>g[i]>>k[i];//读入 cin>>x>>y; for (int i=1;i<=n;i++) if(a[i]<=x&&b[i]<=y&&a[i]+g[i]>=x&&b[i]+k[i]>=y) ans=i;/*地毯要覆盖一点,即左下方点必须 小于指定点的横纵坐标(自己去试试),地毯长度必须大于指定点的横纵坐标 */ cout<<ans<<endl; return 0; }
-
02017-10-03 11:47:41@
#include<iostream>
using namespace std ;
struct ha{
int a,b,g,k,a1,b1;
}d[10000];
int main()
{
int i,n,mm,nn;
freopen("carpet.in","r",stdin);
freopen("carpet.out","w",stdout);
cin>>n;
for(i=1;i<=n;i++)
{
cin>>d[i].a>>d[i].b>>d[i].g>>d[i].k;
d[i].a1=d[i].a+d[i].g;
d[i].b1=d[i].b+d[i].k;
}
cin>>mm>>nn;
for(i=n;i>=1;i++)
{
if(mm>=d[i].a&&mm<=d[i].a1&&nn>=d[i].b&&nn<=d[i].b1)
{
cout<<i<<endl;
return 0;
}
if(i=1)
{
cout<<"-1"<<endl;
return 0;
}
}
} -
02017-09-26 15:56:26@
#include <cstdio>
#include <iostream>
#include <cstdlib>
#define N 10000
using namespace std;
int main()
{
int n,a[N],b[N],x[N],y[N],h,l,t=-1;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i]>>b[i]>>x[i]>>y[i];
}
cin>>h>>l;
for(int i=0;i<n;i++)
{
if(h>=a[i]&&h<=(a[i]+x[i])&&l>=b[i]&&l<=(b[i]+y[i]))
t=i;
}
if(t==-1)
cout<<-1;
else
cout<<t+1;return 0;
} -
02017-08-25 01:45:06@
50 AC 纪念
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <algorithm> using namespace std; int main() { int a[12223][10]={0},n,i,d=-1,x,y; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i][1]); scanf("%d",&a[i][2]); scanf("%d",&a[i][3]); scanf("%d\n",&a[i][4]); } scanf("%d %d",&x,&y); for(i=1;i<=n;i++) { if(x>=a[i][1]&&x<=a[i][1]+a[i][3]&&y>=a[i][2]&&y<=a[i][2]+a[i][4]) d=i; } printf("%d",d); }
-
02017-08-14 11:43:01@
#include <cmath> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,x,y,ans; int a[10000+1]; int b[10000+1]; int c[10000+1]; int d[10000+1]; int main() { //freopen("carpet.in","r",stdin); //freopen("carpet.out","w",stdout); while (~scanf("%d",&n)) { for (int i=1;i<=n;i++) { int d_x,d_y; scanf("%d%d%d%d",&a[i],&b[i],&d_x,&d_y); c[i]=a[i]+d_x,d[i]=b[i]+d_y; } ans=-1; scanf("%d%d",&x,&y); for (int i=1;i<=n;i++) if (a[i]<=x&&x<=c[i]&&b[i]<=y&&y<=d[i]) ans=i; printf("%d\n",ans); } }
-
02017-07-12 21:37:56@
var
x,y,t,i,n:longint;
a,b,c,d:array[1..10000]of longint;
begin
readln(n);
for i:=1 to n do readln(a[i],b[i],c[i],d[i]);
readln(x,y);
for i:=n downto 1 do
if (x>=a[i])and(x<=a[i]+c[i])and(y>=b[i])and(y<=b[i]+d[i]) then begin
t:=i;
break;end;
if t=0 then write(-1) else write(t);
end. -
02017-07-12 21:37:28@
var
x,y,t,i,n:longint;
a,b,c,d:array[1..10000]of longint;
begin
readln(n);
for i:=1 to n do readln(a[i],b[i],c[i],d[i]);
readln(x,y);
for i:=n downto 1 do
if (x>=a[i])and(x<=a[i]+c[i])and(y>=b[i])and(y<=b[i]+d[i]) then begin
t:=i;
break;end;
if t=0 then write(-1) else write(t);
end. -
02017-06-16 21:34:28@
唉,学了这么长时间也就只能AC点简单的模拟题了,55555
#include <iostream> using namespace std; int x[10003]; int y[10003]; int length[10003]; int width[10003]; int main(void) { int n,flag=0,ans; cin>>n; for(int i=0;i<n;i++) { cin>>x[i]>>y[i]>>length[i]>>width[i]; } int p,q; cin>>p>>q; for(int i=0;i<n;i++) { if(x[i]+length[i]>=p&&y[i]+width[i]>=q&&x[i]<=p&&y[i]<=q) { flag=1; ans=i; } } if(flag) cout<<ans+1<<endl; else { cout<<"-1"<<endl; } }
-
02017-04-26 18:38:25@
#include<cstdio>
#include<iostream>
#define MAX 100000using namespace std;
int main(){
int n,a[MAX],b[MAX],g[MAX],k[MAX],x,y,i;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d%d%d%d",&a[i],&b[i],&g[i],&k[i]);
}
scanf("%d%d",&x,&y);
for(i=n-1;i>=-1;i--){
if(i==-1){
printf("-1");
break;
}
if((x>=a[i])&&(x<=a[i]+g[i])&&(y>=b[i])&&(y<=b[i]+k[i])){
printf("%d\n",i+1);
break;
}
}
return 0;
}