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 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

Copy
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 ;
}

最新文章

  1. 【直播】APP全量混淆和瘦身技术揭秘
  2. mysql 分表
  3. Centos 重置密码
  4. IOS searchBar去掉背景
  5. 好吧,CSS3 3D transform变换,不过如此!
  6. Linux系统信息查看
  7. vue防止闪烁
  8. nginx启动过程分析
  9. 四大类NoSQL数据库
  10. Golang安装与环境的配置
  11. mysql----------mysql5.7如何配置主从数据库
  12. BAT等公司必问的8道Java经典面试题,你都会了吗?
  13. Tslib步骤以及出现问题的解决方案【转】
  14. less css框架的学习
  15. Idea2018激活
  16. Talk to customer about the trouble with wireless failure connection。
  17. BP神经网络研究(一)
  18. 前端_basic
  19. 每天一个liunx命令4之 ps -ef ,ps -aux ,ps aux
  20. react dva 表单校验

热门文章

  1. unbuntu禁用ipv6
  2. Mac配置PHP环境
  3. 钓鱼WIFI的防范
  4. Android通过XML来定义Menu
  5. 三种记录 MySQL 所执行过的 SQL 语句的方法
  6. 二 MapReduce 各阶段流程分析
  7. 在VPS上用Outline Manager 建立*** 增强版服务器
  8. Vsftp权限控制(持续增加中)
  9. css3 文字溢出 换行实现方案
  10. 打印机共享 : 客户端 连接服务器打印机时提示&quot;无法连接到打印机“