UVA 12520 Square Garden
https://vjudge.net/problem/UVA-12520
题意:n*n网格中染色m个格子,染色格子的最长轮廓线
贪心
将格子分为4类
1、隔一个选一个,互不相邻的格子
2、4个角上的格子
3、边界除角的格子
4、内部的格子
4类从上到下依次选
1对答案有4的贡献
2对答案无贡献
3对答案有-2的贡献
4对答案有-4的贡献
对n奇偶分类讨论
当n为奇数时,在分左上角的格子在第1类还是第2类讨论
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
freopen("data.txt","r",stdin);
freopen("my.txt","w",stdout);
long long ans1,ans2,n,sum,rest,now,tmp;
while(scanf("%lld%lld",&n,&sum)!=EOF)
{
if(!n) return ;
if(n&)
{
if(sum<=n*n>> || sum<=n*n/+)
{
printf("%lld\n",sum<<);
continue;
}
if(sum<=n*n/+) ans1=n*n/*;
else
{
tmp=sum--n*n/;
ans1=n*n/<<;
rest=n/-<<;
if(tmp<=rest) ans1-=tmp<<;
else
{
ans1-=rest<<;
tmp-=rest;
ans1-=tmp<<;
}
}
ans2=n*n/+<<;
now=n*n/+;
rest=n/<<;
if(sum-now<=rest) ans2-=sum-now<<;
else
{
ans2-=rest<<;
now+=rest;
ans2-=sum-now<<;
}
printf("%lld\n",max(ans1,ans2));
}
else
{
if(sum<=n*n>>)
{
printf("%lld\n",sum<<);
continue;
}
if(sum<=n*n/+)
{
printf("%lld\n",n*n/*);
continue;
}
ans1=n*n>><<;
tmp=sum-n*n/-;
rest=n/-<<;
if(tmp<=rest) ans1-=tmp<<;
else
{
ans1-=rest<<;
tmp-=rest;
ans1-=tmp<<;
}
printf("%lld\n",ans1);
}
}
}
同一种思路大佬的写法就是短
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll l,n,a,b,c,ans;
ll cal()
{
if(n<=a) return n*;
if(n<=a+b) return a*;
if(n<=a+b+c) return a*-(n-a-b)*;
return a*-c*-(n-a-b-c)*;
}
int main()
{
freopen("data.txt","r",stdin);
freopen("std.txt","w",stdout);
while(cin>>l>>n,l||n)
{
if(l%==)
{
a=l*l/;
b=;
c=l/-<<;
ans=cal();
}
else
{
a=l*l/;
b=l== ? :;
c=l== ? :(l-)/*;
ans=cal();
a=l*l/+;
b=;
c=(l-)/*;
ans=max(ans,cal());
}
cout<<ans<<endl;
}
}
UVA 12520 Square Garden的更多相关文章
- UVA 11542 - Square(高斯消元)
UVA 11542 - Square 题目链接 题意:给定一些数字.保证这些数字质因子不会超过500,求这些数字中选出几个,乘积为全然平方数,问有几种选法 思路:对每一个数字分解成质因子后.发现假设要 ...
- UVa 11461 - Square Numbers【数学,暴力】
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 11461 - Square Numbers 数学水题
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- xor方程组消元 UVA 11542 Square
题目传送门 题意:给n个数,选择一些数字乘积为平方数的选择方案数.训练指南题目. 分析:每一个数字分解质因数.比如4, 6, 10, 15,, , , , 令,表示选择第i个数字,那么,如果p是平方数 ...
- UVA 11461 - Square Numbers(水题)
题目链接 #include <cstdio> #include <cstring> #include <string> #include <cmath> ...
- UVA 11461 - Square Numbers
题目:统计区间中的平方数个数. 分析: ... #include <stdio.h> #include <string.h> ]; int main() { int i, a, ...
- UVA 1603 Square Destroyer
题意: 给定一个火柴棒拼成的方格阵,然后去掉一些火柴棒,问至少再去掉几根火柴棒能够让图中一个正方形都没有. 思路: 1. 由于题目中给定了 n 的范围,2 * n * (n + 1) <= 60 ...
- UVA 11542 Square ——线性基
[题目分析] 每个数没有超过500的因子.很容易想到把每一个数表示成一个二进制的数. (0代表该质数的次数为偶数,1代表是奇数) 然后问题转化成了选取一些二进制数,使他们的异或和为0. 高斯消元,2^ ...
- UVa 11542 Square (高斯消元)
题意:给定 n 个数,从中选出一个,或者是多个,使得选出的整数的乘积是完全平方数,求一共有多少种选法,整数的素因子不大于 500. 析:从题目素因子不超过 500,就知道要把每个数进行分解.因为结果要 ...
随机推荐
- J2EE Oa项目上传服务器出现的乱码解决过程
(= =)搞了许久觉得有必要记下来.. 由于我本地的mysql都设置好了,但是服务器的又不能去改它 毕竟还有其他人要用- -: 所以只能是我建的时候去设置一下了, 首先先建数据库 ,表;; creat ...
- hihocoder #1032 : 最长回文子串 Manacher算法
题目链接: https://hihocoder.com/problemset/problem/1032?sid=868170 最长回文子串 时间限制:1000ms内存限制:64MB 问题描述 小Hi和 ...
- java下执行mongodb
1.1连单台mongodb Mongo mg = newMongo();//默认连本机127.0.0.1 端口为27017 Mongo mg = newMongo(ip);//可以指定ip 端口默认 ...
- IBM存储降级告警等一些服务器问题/dd/ethtool
1.IBM存储降级告警 一般两种情况 a.端口降级 例如模块16G->8G(IBM储存端口自适应) b.系统在作raid后,有硬盘损坏,降级 黄灯告警 2. dimm error dimm内存插 ...
- 常用的一些sql
--根据某一列中包括的逗号将一行数据变多行 select a,c from (with test as (select 'abc' a,'1,2,3' c from dual e) select a, ...
- WebUploader 设置单个文件上传
1.导入控件样式文件 <link rel="stylesheet" type="text/css" href="__PUBLIC__/stati ...
- Java知识点整理(二)
List.Set.Map典型实现 HashMap/ConcurrentHashMap Java线程池 Java线程池详解 如何更好的使用JAVA线程池 Spring MVC Spring MVC架构浅 ...
- 超链接提示效果jQuery+CSS+html
我们知道浏览器自带了超链接提示, 只需要在超链接中加入 title 属性就可以了. <a href="#" title="吉大砍人案致1死1伤 受害者死前大喊他手里 ...
- 【数据库_Mysql】查询当前年份的sql
1.本年份 SELECT DATE_FORMAT(NOW(), '%Y'); 2.本月份(显示数字) SELECT DATE_FORMAT(NOW(), '%m'); 3.本月份(显示英文) SELE ...
- BZOJ4888 Tjoi2017异或和(树状数组)
化为前缀和相减.考虑每一位的贡献.则需要快速查询之前有几个数和当前数的差在第k位上为1.显然其与更高位是无关的.于是用BIT维护后k位的数的出现次数,瞎算一算即可. // luogu-judger-e ...