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 前缀和打挂,精度被卡,能水过的题连水法都 ...
随机推荐
- NodeJS学习笔记 进阶 (7)express+session实现简易身份认证(ok)
个人总结: 这篇文章讲解了express框架中如何使用session,主要用了express-session这个包.更多可以参考npm.js来看,读完这篇文章需要10分钟. 摘选自网络: 文档概览 本 ...
- [译] 我最终是怎么玩转了 Vue 的作用域插槽
原文链接:https://juejin.im/post/5c8856e6e51d456b30397f31#comment 原文地址:How I finally got my head around S ...
- Windows 10 计划带来颜文字和Sandbox
在最新的 Window 10 测试版 Build 18305 中,Windows 10 增加了对颜文字(kaomoji)的支持. Kaomoji 是由日本符号序列组成的面脸部表情的名称.虽然有些人,比 ...
- atitit.js 与c# java交互html5化的原理与总结.doc
atitit.js 与c# java交互html5化的原理与总结.doc 1. 实现html5化界面的要解决的策略 1 1.1. Js交互 1 1.2. 动态參数个数 1 1.3. 事件监听 2 2. ...
- doT.js灵活运用之嵌入使用
基础的base_info_area <div id="base_info_area"></div> <script type="text/h ...
- 解决Maven项目相互依赖/循环依赖/双向依赖的问题
转自:https://blog.csdn.net/leolu007/article/details/53079875 添加新随笔很多时候随着项目的膨胀,模块会越来越多 ...
- 关于Javascript的forEach 和 map
本篇博客转载自 https://blog.fundebug.com/2018/02/05/map_vs_foreach/ 如果你已经有使用JavaScript的经验,你可能已经知道这两个看似相同的方法 ...
- 16.C语言可变参数
//可变参数实现多个参数求和 1 #define _CRT_SECURE_NO_WARNINGS #include <stdlib.h> #include <stdio.h> ...
- Sqoop Export原理和详细流程讲解
Sqoop Export原理 Sqoop Export详细流程讲解
- ES6第一节:开发环境的搭建
前言:由于目前浏览器对ES6的支持度不高,需要借助babel将编写好的ES6代码转换成ES5,浏览器才能解析. 需要在NodeJS环境下运行 一. 建立结构:两个文件夹和一个html文件,分别是src ...