A:超级大水题,不解释:
代码:
1 #include2 #include 3 using namespace std; 4 int a,b; 5 int main() 6 { 7 int n,m,ma=0,mi=9999999,mb=9999999; 8 cin>>n>>m; 9 for(int i=0; i >a;12 if(a>ma)ma=a;13 if(a >b;18 if(mb>b)mb=b;19 }20 if(mi*2>ma)ma=mi*2;21 if(ma>=mb)cout<<"-1";22 else cout<
B:很简单,打个标记,dfs解决;
1 #include2 #include 3 #include 4 #define maxn 100005 5 using namespace std; 6 vector ve[maxn]; 7 int belong[maxn],to[maxn]; 8 bool vis[maxn],dead[maxn]; 9 void dfs(int x,int f)10 {11 if(to[x]==0||belong[to[x]]==1||dead[to[x]])return;12 ve[f].push_back(to[x]);13 dfs(to[x],f);14 }15 16 int main()17 {18 int n;19 scanf("%d",&n);20 for(int i=1; i<=n; i++)scanf("%d",&belong[i]);21 for(int i=1; i<=n; i++)22 {23 scanf("%d",&to[i]);24 if(to[i]!=0)25 {26 if(vis[to[i]])27 dead[to[i]]=1;28 else vis[to[i]]=1;29 }30 }31 for(int i=1; i<=n; i++)32 {33 if(belong[i]==1)34 {35 ve[i].push_back(i);36 dfs(i,i);37 }38 }39 int ma=0,k;40 for(int i=1; i<=n; i++)if(ve[i].size()>ma)41 {42 ma=ve[i].size();43 k=i;44 }45 printf("%d\n",ma);46 for(int i=ma-1; i>=0; i--)printf("%d ",ve[k][i]);47 return 0;48 }
C:很简单,排个序,然后按照规则输出就行;
1 #include2 #include 3 #define maxn 100005 4 using namespace std; 5 6 struct bomb 7 { 8 int x,y; 9 bool operator<(const bomb &t)const10 {11 if(abs(x)==abs(t.x))return abs(y) 0?"R":"L");34 }35 if(bo[i].y!=0)36 {37 printf("1 %d ",abs(bo[i].y));38 puts(bo[i].y>0?"U":"D");39 }40 puts("2");41 if(bo[i].x!=0)42 {43 printf("1 %d ",abs(bo[i].x));44 puts(bo[i].x>0?"L":"R");45 }46 if(bo[i].y!=0)47 {48 printf("1 %d ",abs(bo[i].y));49 puts(bo[i].y>0?"D":"U");50 }51 puts("3");52 }53 return 0;54 }