Codeforces 699
Problem A Launch of Collider
题目大意
在x轴上有n个点,坐标均为偶数。每个点或向左移动或向右移动,每秒移动距离为1。
使所有点同时开始移动,求最早有点相遇的时间或无解。
解题分析
对于每一个向右移动的点,找右边最近的一个向左的点。向左移动同理。
正反扫两遍即可。
参考程序
1 #include <map> 2 #include <set> 3 #include <stack> 4 #include <queue> 5 #include <cmath> 6 #include <ctime> 7 #include <string> 8 #include <vector> 9 #include <cstdio> 10 #include <cstdlib> 11 #include <cstring> 12 #include <iostream> 13 #include <algorithm> 14 #pragma comment(linker,"/STACK:102400000,102400000") 15 using namespace std; 16 17 #define N 200008 18 #define V 1008 19 #define E 60008 20 #define lson l,m,rt<<1 21 #define rson m,r+1,rt<<1|1 22 #define clr(x,v) memset(x,v,sizeof(x)); 23 #define LL long long 24 //#define debug 25 const int mo = 1000000007; 26 const int inf = 0x3f3f3f3f; 27 const int INF = 2000000000; 28 /**************************************************************************/ 29 int n; 30 char s[N]; 31 int a[N],ans[N]; 32 int main(){ 33 scanf("%d",&n); 34 scanf("%s",s+1); 35 for (int i=1;i<=n;i++) scanf("%d",&a[i]); 36 int x=-1; 37 for (int i=1;i<=n;i++) 38 if (s[i]=='R') x=a[i]; 39 else 40 { 41 if (x==-1) ans[i]=INF; 42 else ans[i]=(a[i]-x)/2; 43 } 44 x=-1; 45 for (int i=n;i>=1;i--) 46 if (s[i]=='L') x=a[i]; 47 else 48 { 49 if (x==-1) ans[i]=INF; 50 else ans[i]=(x-a[i])/2; 51 } 52 int res=INF; 53 for (int i=1;i<=n;i++) res=min(res,ans[i]); 54 printf("%d ",res==INF ? -1 : res); 55 56 #ifdef debug 57 system("pause"); 58 #endif 59 } 60
Problem B One Bomb
题目大意
有一个n*m的矩形,每一个格子为空地或者为墙壁。 (n,m<=1000)
现在要某点放置一颗炸弹,炸掉所有的墙壁。炸弹的爆炸范围为该点的上下左右两条直线。
给出一种方案或无解。
解题分析
记录一下每行的墙壁数,每列的墙壁数。
枚举每个点是否放置炸弹即可。
参考程序
1 #include <map> 2 #include <set> 3 #include <stack> 4 #include <queue> 5 #include <cmath> 6 #include <ctime> 7 #include <string> 8 #include <vector> 9 #include <cstdio> 10 #include <cstdlib> 11 #include <cstring> 12 #include <iostream> 13 #include <algorithm> 14 #pragma comment(linker,"/STACK:102400000,102400000") 15 using namespace std; 16 17 #define N 1000008 18 #define V 1008 19 #define E 60008 20 #define lson l,m,rt<<1 21 #define rson m,r+1,rt<<1|1 22 #define clr(x,v) memset(x,v,sizeof(x)); 23 #define LL long long 24 //#define debug 25 const int mo = 1000000007; 26 const int inf = 0x3f3f3f3f; 27 const int INF = 2000000000; 28 /**************************************************************************/ 29 30 int n,m,num; 31 int x[V],y[V],mp[V][V]; 32 int main(){ 33 scanf("%d%d",&n,&m); 34 num=0; 35 for (int i=1;i<=n;i++){ 36 char s[V]; 37 scanf("%s",s+1); 38 for (int j=1;j<=m;j++) 39 if (s[j]=='*'){ 40 x[i]++; 41 y[j]++; 42 mp[i][j]=1; 43 num++; 44 } 45 } 46 int ok=0; 47 int tx,ty; 48 for (tx=1;tx<=n;tx++){ 49 for (ty=1;ty<=m;ty++){ 50 int now; 51 if (mp[tx][ty]) now=x[tx]+y[ty]-1; else now=x[tx]+y[ty]; 52 if (now==num){ 53 ok=1; 54 break; 55 } 56 } 57 if (ok) break; 58 } 59 if (ok) printf("YES %d %d ",tx,ty); else printf("NO "); 60 61 #ifdef debug 62 system("pause"); 63 #endif 64 }