热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CodeforcesRound#296(Div.2)A,B,C,D

A-PlayingwithPaper:问一个矩阵最多能被切成多少个正方形。暴力即可#include<map>#include<set>#inc

A - Playing with Paper: 问一个矩阵最多能被切成多少个正方形。暴力即可

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

#define lson l, mid, rt <<1
#define rson mid + 1, r, rt <<1 | 1
#define pi acos(-1.0)
#define eps 1e-8
typedef long long ll;
const int inf = 0x3f3f3f3f;

ll n, m;

int main()
{
    while( cin >> n >> m )
    {
        ll ans = 0;
        while( 1 )
        {
            if( n % m == 0 )
            {
                ans += n / m;
                break;
            }
            ans += n / m;
            n = n - n / m * m;
            swap( n, m );
        }
        cout < 
 
B - Error Correct System :问两个长度相同的串通过交换随意的两个字符能不能使同样位置的不同字符的数尽可能少,输出交换后相同位置的不同的数,如果可以减少的话,输出使减少数量最大的两个位置

对不同的位置的两个字母建边,然后三重循环找答案

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

#define lson l, mid, rt <<1
#define rson mid + 1, r, rt <<1 | 1
#define pi acos(-1.0)
#define eps 1e-8
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 200010;

char a[N], c[N];
int n;

int mat[30][30];

int main()
{
    while(~scanf("%d", &n))
    {
        int cnt = 0;
        int p1, p2;
        memset( mat, -1, sizeof( mat ) );
        scanf("%s %s", a, c);
        for( int i = 0; i  0 )
                {
                    if( mat[j][i] > 0 )
                    {
                        printf("%d\n%d %d\n", cnt-2, mat[i][j], mat[j][i]);
                        OK = 1;
                        break;
                    }
                    if( OK )
                        continue;
                    for( int k = 0; k <26; ++k )
                    {
                        if( mat[j][k] > 0  && k != j )
                        {
                            p1 = mat[i][j];
                            p2 = mat[j][k];
                            OK = 2;
                            break;
                        }
                    }
                }
            }
            if( OK == 1 )
                break;
        }
        if( !OK )
            printf("%d\n-1 -1\n", cnt);
        else if( OK == 2 )
            printf("%d\n%d %d\n", cnt-1, p1, p2);
    }
    return 0;
}
C - Glass Carving 问在切割一个矩阵的过程中,最大小矩阵的面积是多少

首先确定,若某一个子矩阵的面积最大,那么这个矩阵的长和宽在所有的矩阵中,长和宽必定是里面最大的。那么只需要记录和更新矩阵的长和宽即可。可知每次切割矩阵的时候,必定是将某段子长(宽)切成两块,那么删除这段长度,并且同时更新两段新切割出的长度即可,最后输出最大长和宽之积即可

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

#define lson l, mid, rt <<1
#define rson mid + 1, r, rt <<1 | 1
#define pi acos(-1.0)
#define eps 1e-8
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 200010;

set  v, h;//记录切割的点
set  vv, hh;//记录长度
map  V, H;//记录长度的数量
set  :: iterator it, it1;
map  :: iterator mp1, mp2;
int n, m, q;

void init()
{
    V.clear();
    H.clear();
    v.clear();
    h.clear();
    vv.clear();
    hh.clear();
}

int main()
{
    while(~scanf("%d%d%d", &m, &n, &q))
    {
        init();
        v.insert(0);
        v.insert(m);
        h.insert(0);
        h.insert(n);
        V[m]++;
        H[n]++;
        hh.insert(n);
        vv.insert(m);
        while( q-- )
        {
            char op[10];
            int x;
            scanf("%s%d", op, &x);
            if( x == 0 )
                continue;
            if( op[0] == 'H' )
            {
                it1 = h.lower_bound(x);
                it = it1;
                it1--;
                //printf("between: %d %d\n", *it1, *it);
                h.insert(x);
                int xx = *it - *it1;
                //if( H.find( *it - *it1 ) != H.end() )
                //  H.erase( *it - *it1 );
                //H.insert( (*it - x) );
                //H.insert( (x - *it1) );
                if( H[xx] )
                    H[xx]--;
                if( !H[xx] )
                    hh.erase(xx);
                H[ *it - x ]++;
                H[ x - *it1 ]++;
                if( hh.find( *it-x ) == hh.end() )
                    hh.insert( *it - x );
                if( hh.find( x - *it1) == hh.end() )
                    hh.insert( x - *it1 );
            }
            else
            {
                it1 = v.lower_bound(x);
                it = it1;
                it1--;
                //printf("between: %d %d\n", *it1, *it);
                v.insert(x);
                int xx = *it - *it1;
                //if( V.find( *it - *it1 ) != V.end() )
                //  V.erase( *it - *it1 );
                //V.insert( (*it - x) );
                //V.insert( (x - *it1) );
                if( V[xx] )
                    V[xx]--;
                if( !V[xx] )
                    vv.erase(xx);
                V[ *it - x ]++;
                V[ x - *it1 ]++;
                if( vv.find( *it - x) == vv.end() )
                    vv.insert( *it - x );
                if( vv.find( x - *it1) == vv.end() )
                    vv.insert( x - *it1);
            }
            ll ans = (ll) *hh.rbegin() * (ll) *vv.rbegin();
            cout < 
 
D - Clique Problem 给出n个点,每点有两个信息,wi, xi,其中两点满足(x1 - x2) >= w1 + w2,则两点可以连边。问最大的某个集合里面点的数量(集合里面任意两点都可相互到达)。

将x看成坐标轴上点的圆心,w看成该圆的半径,那么条件就转换为,若是坐标轴上两个圆相切或是相离,则认为两个圆可以连边。那么先对所以点排序,根据w+r升序。然后遍历所有的点,每次若是ri - wi > cur(当前最右距离),res++;同时更新最右的cur。

#include 
using namespace std;

const int N = 200010;

struct node{
	int x, r;
}a[N];

int cmp( const node &q, const node &w)
{
	return q.x + q.r = dis ){
				ans++;
				dis = max( dis, a[i].r + a[i].x );
			}
		}
		cout < 
 


推荐阅读
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • 本文介绍了如何使用PHP向系统日历中添加事件的方法,通过使用PHP技术可以实现自动添加事件的功能,从而实现全局通知系统和迅速记录工具的自动化。同时还提到了系统exchange自带的日历具有同步感的特点,以及使用web技术实现自动添加事件的优势。 ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • 本文介绍了P1651题目的描述和要求,以及计算能搭建的塔的最大高度的方法。通过动态规划和状压技术,将问题转化为求解差值的问题,并定义了相应的状态。最终得出了计算最大高度的解法。 ... [详细]
  • 本文介绍了一个题目的解法,通过二分答案来解决问题,但困难在于如何进行检查。文章提供了一种逃逸方式,通过移动最慢的宿管来锁门时跑到更居中的位置,从而使所有合格的寝室都居中。文章还提到可以分开判断两边的情况,并使用前缀和的方式来求出在任意时刻能够到达宿管即将锁门的寝室的人数。最后,文章提到可以改成O(n)的直接枚举来解决问题。 ... [详细]
  • 本文讨论了一个数列求和问题,该数列按照一定规律生成。通过观察数列的规律,我们可以得出求解该问题的算法。具体算法为计算前n项i*f[i]的和,其中f[i]表示数列中有i个数字。根据参考的思路,我们可以将算法的时间复杂度控制在O(n),即计算到5e5即可满足1e9的要求。 ... [详细]
  • This article discusses the efficiency of using char str[] and char *str and whether there is any reason to prefer one over the other. It explains the difference between the two and provides an example to illustrate their usage. ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 云原生边缘计算之KubeEdge简介及功能特点
    本文介绍了云原生边缘计算中的KubeEdge系统,该系统是一个开源系统,用于将容器化应用程序编排功能扩展到Edge的主机。它基于Kubernetes构建,并为网络应用程序提供基础架构支持。同时,KubeEdge具有离线模式、基于Kubernetes的节点、群集、应用程序和设备管理、资源优化等特点。此外,KubeEdge还支持跨平台工作,在私有、公共和混合云中都可以运行。同时,KubeEdge还提供数据管理和数据分析管道引擎的支持。最后,本文还介绍了KubeEdge系统生成证书的方法。 ... [详细]
  • 本文介绍了解决二叉树层序创建问题的方法。通过使用队列结构体和二叉树结构体,实现了入队和出队操作,并提供了判断队列是否为空的函数。详细介绍了解决该问题的步骤和流程。 ... [详细]
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • JDK源码学习之HashTable(附带面试题)的学习笔记
    本文介绍了JDK源码学习之HashTable(附带面试题)的学习笔记,包括HashTable的定义、数据类型、与HashMap的关系和区别。文章提供了干货,并附带了其他相关主题的学习笔记。 ... [详细]
  • 本文由编程笔记#小编整理,主要介绍了关于数论相关的知识,包括数论的算法和百度百科的链接。文章还介绍了欧几里得算法、辗转相除法、gcd、lcm和扩展欧几里得算法的使用方法。此外,文章还提到了数论在求解不定方程、模线性方程和乘法逆元方面的应用。摘要长度:184字。 ... [详细]
author-avatar
俺是胖墩墩_499
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有