手贱去开了abc,这么无聊。直接arc啊

C - 4-adjacent


Time limit : 2sec / Memory limit : 256MB

Score : 400 points

Problem Statement

We have a sequence of length Na=(a1,a2,…,aN). Each ai is a positive integer.

Snuke's objective is to permute the element in a so that the following condition is satisfied:

  • For each 1≤iN−1, the product of ai and ai+1 is a multiple of 4.

Determine whether Snuke can achieve his objective.

Constraints

  • 2≤N≤105
  • ai is an integer.
  • 1≤ai≤109

Input

Input is given from Standard Input in the following format:

N
a1 a2 aN

Output

If Snuke can achieve his objective, print Yes; otherwise, print No.


Sample Input 1

Copy
3
1 10 100

Sample Output 1

Copy
Yes

One solution is (1,100,10).


Sample Input 2

Copy
4
1 2 3 4

Sample Output 2

Copy
No

It is impossible to permute a so that the condition is satisfied.


Sample Input 3

Copy
3
1 4 1

Sample Output 3

Copy
Yes

The condition is already satisfied initially.


Sample Input 4

Copy
2
1 1

Sample Output 4

Copy
No

Sample Input 5

Copy
6
2 7 1 8 2 8

Sample Output 5

Copy
Yes

给你一个序列,通过你的安排让这个序列满足相邻两个数的乘积是4的倍数,如果有奇数的话,而且4的倍数个数+1还比奇数多,没有2的倍数,比如1 4 1就是成立的,

2的倍数很多,这些放哪都行,只要奇数和4的倍数能凑就行

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
int a[N];
int main()
{
int n;
cin>>n;
int cnt4=,cnt2=;
for(int i=; i<n; i++)
{
cin>>a[i];
a[i]%=;
if(a[i]==)
cnt4++;
else if(a[i]==)
cnt2++;
}
int cnt=n-cnt2-cnt4;
if(cnt2)
{
if(cnt4>=cnt){
cout<<"Yes";
return ;
}
}
else
{
if(cnt4&&(cnt4+>=cnt)){
cout<<"Yes";
return ;
}
}
cout<<"No";
return ;
}

D - Grid Coloring


Time limit : 2sec / Memory limit : 256MB

Score : 400 points

Problem Statement

We have a grid with H rows and W columns of squares. Snuke is painting these squares in colors 12N. Here, the following conditions should be satisfied:

  • For each i (1≤iN), there are exactly ai squares painted in Color i. Here, a1+a2+…+aN=HW.
  • For each i (1≤iN), the squares painted in Color i are 4-connected. That is, every square painted in Color i can be reached from every square painted in Color i by repeatedly traveling to a horizontally or vertically adjacent square painted in Color i.

Find a way to paint the squares so that the conditions are satisfied. It can be shown that a solution always exists.

Constraints

  • 1≤H,W≤100
  • 1≤NHW
  • ai≥1
  • a1+a2+…+aN=HW

Input

Input is given from Standard Input in the following format:

H W
N
a1 a2 aN

Output

Print one way to paint the squares that satisfies the conditions. Output in the following format:

c11  c1W
:
cH1 cHW

Here, cij is the color of the square at the i-th row from the top and j-th column from the left.


Sample Input 1

Copy
2 2
3
2 1 1

Sample Output 1

Copy
1 1
2 3

Below is an example of an invalid solution:

1 2
3 1

This is because the squares painted in Color 1 are not 4-connected.


Sample Input 2

Copy
3 5
5
1 2 3 4 5

Sample Output 2

Copy
1 4 4 4 3
2 5 4 5 3
2 5 5 5 3

Sample Input 3

Copy
1 1
1
1

Sample Output 3

Copy
1


我的做法莫名wa,换了个做法ac,也差不到原因,反正注意下就好

就是给你n个数,代表第几个数有几个,他们必须是联通的,特判题
#include <bits/stdc++.h>
using namespace std;
vector<int>a[];
int main()
{
int h,w;
cin>>h>>w;
int n;
cin>>n;
int f=;
for(int i=; i<n; i++)
{
int x;
scanf("%d",&x);
for(int j=;j<x;j++)
a[f/w].push_back(i+),f++;
} for(int i=; i<h; i++)
{
if(i&)reverse(a[i].begin(),a[i].end());
printf("%d",a[i][]);
for(int j=; j<w; j++)
printf(" %d",a[i][j]);
printf("\n");
}
return ;
}

E - Young Maids


Time limit : 2sec / Memory limit : 256MB

Score : 800 points

Problem Statement

Let N be a positive even number.

We have a permutation of (1,2,…,N)p=(p1,p2,…,pN). Snuke is constructing another permutation of (1,2,…,N)q, following the procedure below.

First, let q be an empty sequence. Then, perform the following operation until p becomes empty:

  • Select two adjacent elements in p, and call them x and y in order. Remove x and y from p (reducing the length of p by 2), and insert x and y, preserving the original order, at the beginning of q.

When p becomes empty, q will be a permutation of (1,2,…,N).

Find the lexicographically smallest permutation that can be obtained as q.

Constraints

  • N is an even number.
  • 2≤N≤2×105
  • p is a permutation of (1,2,…,N).

Input

Input is given from Standard Input in the following format:

N
p1 p2 pN

Output

Print the lexicographically smallest permutation, with spaces in between.


Sample Input 1

Copy
4
3 2 4 1

Sample Output 1

Copy
3 1 2 4

The solution above is obtained as follows:

p q
(3,2,4,1) ()
(3,1) (2,4)
() (3,1,2,4)

Sample Input 2

Copy
2
1 2

Sample Output 2

Copy
1 2

Sample Input 3

Copy
8
4 6 3 2 8 5 7 1

Sample Output 3

Copy
3 1 2 7 4 6 8 5

The solution above is obtained as follows:

p q
(4,6,3,2,8,5,7,1) ()
(4,6,3,2,7,1) (8,5)
(3,2,7,1) (4,6,8,5)
(3,1) (2,7,4,6,8,5)
()

(3,1,2,7,4,6,8,5)


每次取两个数,然后把这两个相邻数放到q里,使生成的q字典序最小
这个涉及到区间查询,可以用RMQor线段树。但是那两个数要怎么维护呢,用优先队列?
然后怎么做呢?卿学姐代码做法%一波
 
 

最新文章

  1. DataSet集合直接根据传入的类转List&lt;T&gt;集合
  2. Mina、Netty、Twisted一起学(七):发布/订阅(Publish/Subscribe)
  3. 【搬运工】NOIP吧置顶贴
  4. LazyLoad使用注意
  5. .net开发微信公众平台
  6. Android-深入理解android自定义属性(AttributeSet,TypedArray)
  7. @ExceptionHandler
  8. java日期格式的转换
  9. 【python,threading】python多线程
  10. JMeter入门(1):JMeter总体介绍及组件介绍
  11. 7-http1.1和2.0的区别?
  12. cocos2d-x创建场景
  13. spring HttpServletRequest 简介
  14. 通过web对.exe程序进行更新和修改
  15. java ee Servlet 开发框架分享
  16. 将html table 转成 excel
  17. SpringBoot 上传文件夹
  18. php 的文件操作类
  19. Visual Studio color schemes
  20. HTML一些有趣的东西

热门文章

  1. Python2和Python3语法区别
  2. vue搭建骨架屏步骤配置
  3. python基础教程总结15——3 XML构建网址
  4. 字符串的驻留(String Interning)
  5. OO作业第三单元总结
  6. 安装IAR ewarm
  7. python 产生随机数
  8. C# 替换去除HTML标记方法(正则表达式)
  9. 在ASP.NET项目中的web.config文件里配置数据库连接并在程序代码中获取连接字符串
  10. iOS与JS相互传值与交互