Frozen_Fire @ 2018-10-29 20:58:51
using namespace std; const int SIZE=1003; int book[SIZE]; int people[2][SIZE]; int ans[SIZE]; int same(int book,int people,int len){ bool pd=true; while(len>0){ if(book%10!=people%10){ pd=false; break; } else{ book=book/10; people=people/10; len--; } } return pd; } int main(){ int n,m; cin>>n>>m; for(int i=0;i<n;i++) cin>>book[i]; for(int i=0;i<m;i++) cin>>people[0][i]>>people[1][i]; for(int i=0;i<m;i++){ int min=2e9; for(int j=0;j<m;j++){ if(book[j]>=people[1][i]){ if(same(book[j],people[1][i],people[0][i])){ if(book[j]<min){ min=book[j]; } } } } if(min>2e8){ ans[i]=-1; } else{ ans[i]=min; } } for(int i=0;i<m;i++) cout<<ans[i]<<endl; return 0; }
by Dispwnl @ 2018-10-29 21:04:01
希望更丰富的展现?使用Markdown
by tryrtj @ 2018-10-29 21:05:04
希望更丰富的展现?使用Markdown
by wwz20050323 @ 2018-10-29 21:05:32
#include<stdio.h>
int a[1001],b[1001],c[1001];
void abcd(int l,int r)
{int i=l,j=r,t;
int p=a[(l+r)/2];
while(i<=j)
{
while(a[i]<p)
{i++;}
while(a[j]>p)
{j--;}
if(i<=j)
{t=a[i];
a[i]=a[j];
a[j]=t;
i++;
j--;}
}
if(l<j)
abcd(l,j);
if(i<r)
abcd(i,r); }
int main()
{
int n,q,i,j,t1,t2,t3;
scanf("%d%d",&n,&q);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=q;i++)
scanf("%d%d",&b[i],&c[i]);
abcd(1,n);
for(j=1;j<=q;j++)
for(i=1;i<=n;i++)
{t1=1;
t2=b[j];
while(t2)
{t2--;
t1*=10;}
if(a[i]%t1==c[j])
{printf("%d\n",a[i]);
break;}
if(i==n)
printf("-1\n");}
return 0;
}
by 庄庄庄庄乜 @ 2018-10-29 21:17:46
这是什么神仙代码
by AFO蒟蒻选手 @ 2018-11-05 11:46:19
#include<stdio.h>
int a[1001],b[1001],c[1001];
void abcd(int l,int r){
int i=l,j=r,t;int p=a[(l+r)/2];
while(i<=j)
{
while(a[i]<p)i++;
while(a[j]>p)j--;
if(i<=j){
t=a[i];
a[i]=a[j];
a[j]=t;
i++;
j--;
}
}
if(l<j)abcd(l,j);
if(i<r)abcd(i,r);
}
int main()
{
int n,q,i,j,t1,t2,t3;
scanf("%d%d",&n,&q);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=q;i++)
scanf("%d%d",&b[i],&c[i]);
abcd(1,n);
for(j=1;j<=q;j++)
for(i=1;i<=n;i++){
t1=1;
t2=b[j];
while(t2){
t2--;
t1*=10;
}
if(a[i]%t1==c[j]){
printf("%d\n",a[i]);
break;
}
if(i==n)printf("-1\n");
}
return 0;
}
by AFO蒟蒻选手 @ 2018-11-05 11:47:39
这码风真香毒
脑瓜疼