Atcoder ABC 071 C,D
C - Make a Rectangle
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
We have N sticks with negligible thickness. The length of the i-th stick is Ai.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.
Constraints
- 4≤N≤105
- 1≤Ai≤109
- Ai is an integer.
Input
Input is given from Standard Input in the following format:
N
A1 A2 ... AN
Output
Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.
Sample Input 1
6
3 1 2 4 2 1
Sample Output 1
2
1×2 rectangle can be formed.
Sample Input 2
4
1 2 3 4
Sample Output 2
0
No rectangle can be formed.
Sample Input 3
10
3 3 3 3 4 4 4 5 5 5
Sample Output 3
20
挑最长边即可,并且最长边最少的两条
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
const int maxn=1e6+;
struct cmp
{
bool operator()(const ll &a,const ll &b)
{
return a>b;
}
};
multiset<ll,cmp>s;
multiset<ll>::iterator it;
priority_queue<ll,vector<ll> >q;
ll cnt,x,n;
int main()
{
while(scanf("%lld",&n)!=EOF)
{
s.clear();
for(int i=;i<n;i++)
{
scanf("%lld",&x);
s.insert(x);
}
x=;
for(it=s.begin();it!=s.end();it++)
{
if(*it==x) cnt++;
else x=*it,cnt=;
if(cnt==) q.push(x),cnt=;
}
if(q.size()<) printf("0\n");
else x=q.top(),q.pop(),printf("%lld\n",x*q.top());
while(!q.empty()) q.pop();
}
return ;
}
D - Coloring Dominoes
Time limit : 2sec / Memory limit : 256MB
Score : 400 points
Problem Statement
We have a board with a 2×N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1×2 or 2×1 square.
Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoes that are adjacent by side should be painted by different colors. Here, it is not always necessary to use all three colors.
Find the number of such ways to paint the dominoes, modulo 1000000007.
The arrangement of the dominoes is given to you as two strings S1 and S2 in the following manner:
- Each domino is represented by a different English letter (lowercase or uppercase).
- The j-th character in Si represents the domino that occupies the square at the i-th row from the top and j-th column from the left.
Constraints
- 1≤N≤52
- |S1|=|S2|=N
- S1 and S2 consist of lowercase and uppercase English letters.
- S1 and S2 represent a valid arrangement of dominoes.
Input
Input is given from Standard Input in the following format:
N
S1
S2
Output
Print the number of such ways to paint the dominoes, modulo 1000000007.
Sample Input 1
3
aab
ccb
Sample Output 1
6
There are six ways as shown below:
Sample Input 2
1
Z
Z
Sample Output 2
3
Note that it is not always necessary to use all the colors.
Sample Input 3
52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn
Sample Output 3
958681902
每次都和之前方块的状态有关。
1.竖+竖:ans=ans*2;
2.竖+横:ans=ans*2;
3.横+竖:ans=ans*1;
4.横+横;ans=ans*3;(上1下2,则只可能:1.上2下1,2.上3下1,3.上2下3)
开始时:若为竖C(3,1),若为横:C(3,2).
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 1044266558
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
const int maxn=1e6+;
char a[],b[];
int flag,i,n;
ll ans;
int main()
{
while(scanf("%d %s %s",&n,a,b)!=EOF)
{
ans=,i=;
if(a[i]==b[i]) i++,ans=ans*%MOD,flag=;
else i+=,ans=ans*%MOD,flag=;
while(i<n)
{
if(a[i]==b[i])
{
if(flag) ans=ans*%MOD,i++;
else flag^=,i++;
}
else
{
if(flag) ans=ans*%MOD,flag^=,i+=;
else ans=ans*%MOD,i+=;
}
}
printf("%lld\n",ans);
}
return ;
}
Atcoder ABC 071 C,D的更多相关文章
- ATCODER ABC 099
ATCODER ABC 099 记录一下自己第一场AK的比赛吧...虽然还是被各种踩... 只能说ABC确实是比较容易. A 题目大意 给你一个数(1~1999),让你判断它是不是大于999. Sol ...
- Atcoder ABC 141
Atcoder ABC 141 A - Weather Prediction SB题啊,不讲. #include<iostream> #include<cstdio> #inc ...
- Atcoder ABC 139E
Atcoder ABC 139E 题意: n支球队大循环赛,每支队伍一天只能打一场,求最少几天能打完. 解法: 考虑抽象图论模型,既然一天只能打一场,那么就把每一支球队和它需要交手的球队连边. 求出拓 ...
- Atcoder ABC 139D
Atcoder ABC 139D 解法: 等差数列求和公式,记得开 $ long long $ CODE: #include<iostream> #include<cstdio> ...
- Atcoder ABC 139C
Atcoder ABC 139C 题意: 有 $ n $ 个正方形,选择一个起始位置,使得从这个位置向右的小于等于这个正方形的高度的数量最多. 解法: 简单递推. CODE: #include< ...
- Atcoder ABC 139B
Atcoder ABC 139B 题意: 一开始有1个插口,你的插排有 $ a $ 个插口,你需要 $ b $ 个插口,问你最少需要多少个插排. 解法: 暴力模拟. CODE: #include< ...
- Atcoder ABC 139A
Atcoder ABC 139A 题意: 给你两个字符串,记录对应位置字符相同的个数 $ (n=3) $ 解法: 暴力枚举. CODE: #include<iostream> #inclu ...
- atcoder abc 244
atcoder abc 244 D - swap hats 给定两个 R,G,B 的排列 进行刚好 \(10^{18}\) 次操作,每一次选择两个交换 问最后能否相同 刚好 \(10^{18}\) 次 ...
- AtCoder ABC 250 总结
AtCoder ABC 250 总结 总体 连续若干次一样的结果:30min 切前 4 题,剩下卡在 T5 这几次卡在 T5 都是一次比一次接近, 什么 dp 前缀和打挂,精度被卡,能水过的题连水法都 ...
随机推荐
- 为什么 linux 上不能用 localhost 链接数据库?
因为 linux 连接的时候不是通过 tcp 协议,而是通过 sockect 来连接.所以 写localhost 之后就会默认去找 sockect 链接[此文件在 /var/lib/mysq ...
- Hope is a good thing, maybe the best of things and no good thing ever dies !
- unity 5.6.1 Oculus手柄输入问题
unity文档中提到 轴的 ID 是5和6,但是测试后发现,ID是6和7,很坑 void Update () { if (Input.GetKeyDown(KeyCode.JoystickButton ...
- POJ 2826 An Easy Problem!(简单数论)
Description Have you heard the fact "The base of every normal number system is 10" ? Of co ...
- [Recompose] Create Stream Behaviors to Push Props in React Components with mapPropsStream
Rather than using Components to push streams into other Components, mapPropsStream allows you to cre ...
- java教程(五)SSH框架-配置
前言:从这篇博客開始我将继续讲述Java教程:SSH篇.主要内容环绕SSH框架分析与搭建,今天先简介一下SSH的配置. SSH配置顺序是: spring-->hibernate-->str ...
- Linux 内核源码(kernel source)
查看内核的发行版:uname -r(--kernel-release) $ uname -r 4.4.0-78-generic 内核源码所在的位置:/usr/src $ cd /usr/src $ l ...
- 源码编译安装Nginx全程视频演示
基本步骤: 1.首先停止现有web系统, #/etc/init.d/apache2 stop 2.将源码拷贝到/usr/local/src #cp /home/ditatompel/Public/Ng ...
- CentOS6.x操作系统自带的 DM Multipath(DMMP)多路径软件配置说明。
CentOS系统下的多路径软件是操作系统自带的 DM Multipath(DMMP)工具.------------------------------------------------------- ...
- ES6学习笔记(五)函数的扩展
1.函数参数的默认值 1.1基本用法 ES6 之前,不能直接为函数的参数指定默认值,只能采用变通的方法. function log(x, y) { y = y || 'World'; console. ...