蚂蚁出界了我没有标记居然可以过样例?还有25分?GG
补上标记就A了,2014真题真的水,蓝桥杯啊蓝桥杯!!
1 #include <cmath> 2 #include <cstdio> 3 #include <iostream> 4 #include <algorithm> 5 using namespace std; 6 struct ant{double x;int t,s,o;}a[50];int n; 7 const double eps=1e-9; 8 double len(){ 9 double ans=100; 10 for(int i=1;i<=n;i++) 11 for(int j=1;j<=n;j++) 12 if(!a[i].o&&!a[j].o&&(a[i].x<a[j].x&&a[i].t==1&&a[j].t==0)){ 13 ans=min(ans,fabs(a[i].x-a[j].x)/2); 14 } 15 return ans; 16 } 17 void move(double l){ 18 for(int i=1;i<=n;i++) 19 if(!a[i].o) 20 if(a[i].t==1)a[i].x+=l; 21 else a[i].x-=l; 22 } 23 void trun(){ 24 for(int i=1;i<=n;i++) 25 for(int j=1;j<=n;j++) 26 if(!a[i].o&&!a[j].o&&fabs(a[i].x-a[j].x)<eps){ 27 swap(a[i].t,a[j].t); 28 if(a[i].s||a[j].s) 29 a[i].s=a[j].s=1; 30 } 31 } 32 int del(){ 33 int ans=0; 34 for(int i=1;i<=n;i++) 35 if(!a[i].o&&(a[i].x<0||fabs(a[i].x)<eps||a[i].x>100||fabs(a[i].x-100)<eps)) 36 ans++,a[i].o=1; 37 return ans; 38 } 39 int calc(){ 40 int ans=0; 41 for(int i=1;i<=n;i++)if(a[i].s)ans++; 42 return ans; 43 } 44 int main(){ 45 cin>>n; 46 double x; 47 for(int i=1;i<=n;i++){ 48 cin>>x; 49 a[i].x=x>0?x:-x; 50 a[i].t=x>0?1:0; 51 a[i].s=i==1?1:0; 52 a[i].o=0; 53 } 54 for(int cnt=n;cnt;){ 55 double l=len(); 56 move(l); 57 trun(); 58 cnt-=del(); 59 } 60 cout<<calc()<<endl; 61 return 0; 62 }