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 前缀和打挂,精度被卡,能水过的题连水法都 ...
随机推荐
- 《剑指offer》栈的压入、弹出序列
一.题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压 ...
- 创建支持SSH服务的镜像
一.基于commit命令创建 docker commit CONTAINER [REPOSITORY [:TAG]] 1.使用ubuntu镜像创建一个容器 docker run -it ubuntu ...
- bzoj2100 [Usaco2010 DEC]Apple Delivery苹果贸易
题目描述 一张P个点的无向图,C条正权路.CLJ要从Pb点(家)出发,既要去Pa1点NOI赛场拿金牌,也要去Pa2点CMO赛场拿金牌.(途中不必回家)可以先去NOI,也可以先去CMO.当然神犇CLJ肯 ...
- POJ-2142 The Balance 扩展欧几里德(+绝对值和最小化)
题目链接:https://cn.vjudge.net/problem/POJ-2142 题意 自己看题吧,懒得解释 思路 第一部分就是扩展欧几里德 接下来是根据 $ x=x_0+kb', y=y_0- ...
- [NOIP2016普及组]魔法阵
题目:洛谷P2119.Vijos P2012.codevs5624. 题目大意:有n件物品,每件物品有个魔法值.要求组成魔法阵(Xa,Xb,Xc,Xd),该魔法阵要满足Xa<Xb<Xc&l ...
- conda常用命令,如何在conda环境中安装gym库?
查看已安装的环境: conda info -e 或 conda env list 创建新环境gymlab: conda create -n gymlab python=3.5 激活环境gymlab: ...
- cmd 操作命令
1)cd 操作文件目录的 cd path #进入path cd / #返回到当前盘符的根目录 cd .. #返回到上级目录 2)dir 显示当前目录 dir #显示当前目录下的文件夹 dir path ...
- 紫书 例题 10-25 UVa 1363(找规律)
可以发现余数是成一段一段的等差数列的. 在商数同的时候,余数是成首项为第一个数的余数,公差 为商数的等差数列. 利用这个性质求解即可. #include<cstdio> #include& ...
- photoshop快捷键汇总
图层应用相关快捷键: 复制图层:Ctrl+j 盖印图层:Ctrl+Alt+Shift+E 向下合并图层:Ctrl+E 合并可见图层:Ctrl+Shift+E 激活上一图层:Alt+中括号(]) 激活下 ...
- 把握linux内核设计思想(三):下半部机制之软中断
[版权声明:尊重原创.转载请保留出处:blog.csdn.net/shallnet,文章仅供学习交流,请勿用于商业用途] 中断处理程序以异步方式执行,其会打断其它重要代码,其执行时该中 ...