zoukankan      html  css  js  c++  java
  • 2014年百度之星程序设计大赛

    1001

    暴力

    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    const int maxn = 100100;
    int ll[maxn], rr[maxn];
    struct node
    {
    	int x, y, bj;
    }e[maxn];
    
    
    int main()
    {
    	int cas = 1;
    	int T;
    	scanf("%d", &T);
    	int n;
    	while(T--)
    	{
    		scanf("%d", &n);
    		for(int i = 1; i <= n; i++)
    		{
    			scanf("%d %d", &e[i].x, &e[i].y);
    			if(e[i].y == 0)
    				e[i].bj = 0;
    			else
    				e[i].bj = 1;
    			//c[i] = e[i].y;
    		}
    		int now = -1;
    		for(int i = 1; i <= n; i++)
    		{
    			if(e[i].y != 0)
    				now = i;
    			ll[i] = now;
    		}
    		now = -1;
    		for(int i = n; i >= 1; i--)
    		{
    			if(e[i].y != 0)
    				now = i;
    			rr[i] = now;
    		}
    		for(int i = 1; i <= n; i++)
    		{
    			if(e[i].bj == 0)
    			{
    				if(ll[i] != -1 && rr[i] != -1)
    				{
    					int s1 = abs(e[i].x - e[ll[i]].x);
    					int s2 = abs(e[i].x - e[rr[i]].x);
    					if(s1 > s2)
    						e[i].y = e[rr[i]].y;
    					else if(s1 < s2)
    						e[i].y = e[ll[i]].y;
    					else
    					{
    						if(e[ll[i]].y > e[rr[i]].y)
    							e[i].y = e[ll[i]].y;
    						else
    							e[i].y = e[rr[i]].y;
    					}
    				}
    				else if(ll[i] != -1)
    				{
    					e[i].y = e[ll[i]].y;
    				}
    				else
    				{
    					e[i].y = e[rr[i]].y;
    				}
    			}
    		}
    		int m;
    		scanf("%d", &m);
    		printf("Case #%d:
    ", cas++);
    		while(m--)
    		{
    			char str[10];
    			scanf("%s", str);
    			if(str[0] == 'Q')
    			{
    				for(int i = 1; i <= n; i++)
    				{
    					if(e[i].bj == 0)
    					{
    						if(ll[i] != -1 && rr[i] != -1)
    						{
    							int s1 = abs(e[i].x - e[ll[i]].x);
    							int s2 = abs(e[i].x - e[rr[i]].x);
    							if(s1 > s2)
    								e[i].y = e[rr[i]].y;
    							else if(s1 < s2)
    								e[i].y = e[ll[i]].y;
    							else
    							{
    								if(e[ll[i]].y > e[rr[i]].y)
    									e[i].y = e[ll[i]].y;
    								else
    									e[i].y = e[rr[i]].y;
    							}
    						}
    						else if(ll[i] != -1)
    						{
    							e[i].y = e[ll[i]].y;
    						}
    						else
    						{
    							e[i].y = e[rr[i]].y;
    						}
    					}
    				}
    				int x, sum = 0;
    				scanf("%d", &x);
    				for(int i  = 1; i <= n; i++)
    					if(e[i].y <= x)
    						sum++;
    				printf("%d
    ", sum);
    			}
    			else
    			{
    				int x, y;
    				scanf("%d %d", &x, &y);
    				e[x+1].y = y;
    			}
    		}
    	}
    	return 0;
    }


  • 相关阅读:
    web前端网站收藏
    wordpress安装(ubuntu+nginx+php+mariadb)
    硬盘分区表知识——详解硬盘MBR
    useradd添加用户
    闭包closure this
    什么是同步加载与异步加载
    css 两个span标签在同一行,高度不一样
    CSS label之间存在间距
    JS中如何跳出循环/结束遍历
    el-checkbox-group 无法选中
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/3781767.html
Copyright © 2011-2022 走看看