• 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;
    }


  • 相关阅读:
    CSS清除浮动的方法
    JS获取元素属性、样式getComputedStyle()和currentStyle方法兼容性问题
    数据类型真假的问题
    数据类型——方法总结(可能有不对的)
    attr()与setAttribute()的区别
    wampserver 2.5多站点配置
    php常用函数(持续中)
    php中环境变量
    编码转换
    php中rsa加密及解密和签名及验签
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/3781767.html
Copyright © 2020-2023  润新知