• Codeforces Round #335 (Div. 2)


    水 A - Magic Spheres

    这题也卡了很久很久,关键是“至少”,所以只要判断多出来的是否比需要的多就行了。

    #include <bits/stdc++.h>
    using namespace std;
    
    #define lson l, mid, o << 1
    #define rson mid + 1, r, o << 1 | 1
    typedef long long ll;
    const int N = 1e5 + 5;
    const int INF = 0x3f3f3f3f;
    
    int main(void)	{
    	int a, b, c;
    	int x, y, z;
    	scanf ("%d%d%d", &a, &b, &c);
    	scanf ("%d%d%d", &x, &y, &z);
    	bool flag = true;
    	if (a < x || b < y || c < z)	flag = false;
    	int s1 = a + b + c;
    	int s2 = x + y + z;
    	if (flag)	puts ("Yes");
    	else if (s1 < s2)	puts ("No");
    	else	{
    		int less = 0, more = 0;
    		if (a < x)	less += x - a;
    		else	{
    			more += (a - x)	/ 2;
    		}
    		if (b < y)	less += y - b;
    		else	{
    			more += (b - y) / 2;
    		}
    		if (c < z)	less += z - c;
    		else	{
    			more += (c - z) / 2;
    		}
    		if (more >= less)	puts ("Yes");
    		else	puts ("No");
    	}
    
    	return 0;
    }
    

    模拟 B - Testing Robots

    题意:机器人按照指令走,问有几个格子能使的在第i步使机器人爆炸。

    分析:没什么难的,走过了就vis掉。比赛时C做的人多,B没读懂放弃了。。

    #include <bits/stdc++.h>
    using namespace std;
    
    #define lson l, mid, o << 1
    #define rson mid + 1, r, o << 1 | 1
    typedef long long ll;
    const int N = 1e5 + 5;
    const int INF = 0x3f3f3f3f;
    char str[N];
    bool vis[505][505];
    int ans[N];
    int n, m, x, y;
    
    int main(void)	{
    	scanf ("%d%d%d%d", &n, &m, &x, &y);
    	scanf ("%s", str + 1);
    	int len = strlen (str + 1);
        str[0] = '#';   ans[len] = n * m;
    	for (int i=0; i<len; ++i)	{
    		if (i != 0)	{
    			if (str[i] == 'U' && x > 1)	x--;
    			else if (str[i] == 'D' && x < n)	x++;
    			else if (str[i] == 'L' && y > 1)	y--;
    			else if (str[i] == 'R' && y < m)   y++;
    		}
            if (vis[x][y])  ans[i] = 0;
            else    {
                vis[x][y] = true;
                ans[i] = 1; ans[len]--;
            }
    	}
        for (int i=0; i<=len; ++i)  {
            printf ("%d%c", ans[i], i == len ? '
    ' : ' ');
        }
    
    	return 0;
    }
    

      

    构造+贪心 C - Sorting Railway Cars

    题意:每一辆车可以去头或者尾,问最少几次能使排列有序

    分析:贪心的思想,把相邻数字(LIS的不一定是相邻的,有问题)排列已经有序的不动,其他的都只要动一次就能有序。

    #include <bits/stdc++.h>
    using namespace std;
    
    #define lson l, mid, o << 1
    #define rson mid + 1, r, o << 1 | 1
    typedef long long ll;
    const int N = 1e5 + 5;
    const int INF = 0x3f3f3f3f;
    int a[N], p[N];
    
    int main(void)	{
    	int n;	scanf ("%d", &n);
    	for (int i=1; i<=n; ++i)	{
    		scanf ("%d", &a[i]);	p[a[i]] = i;
    	}
    	int ans = 1, len = 1;
    	for (int i=2; i<=n; ++i)	{
    		if (p[i] > p[i-1])	len++;
    		else	len = 1;
    		ans = max (ans, len);
    	}
    	printf ("%d
    ", n - ans);
    
    	return 0;
    }
    

      

    编译人生,运行世界!
  • 相关阅读:
    最好用的html复制插件——Clipboard.js
    最好用的轮播插件——Swiper.js
    媒体查询
    函数防抖和节流
    JQ增删改查localStorage实现搜索历史功能
    vscode如何设置html模板
    js中innerHTML、outerHTML、innerText、outerText的区别
    JS实现一个简单的网页钟表
    Sql Server 2014完全卸载
    照片尺寸大小怎样换算?
  • 原文地址:https://www.cnblogs.com/Running-Time/p/5042450.html
Copyright © 2020-2023  润新知