GVKun编程网logo

Codeforces Round #436 (Div. 2) Make a Permutation!

10

如果您对CodeforcesRound#436(Div.2)MakeaPermutation!感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解CodeforcesRound#436(Div.2)

如果您对Codeforces Round #436 (Div. 2) Make a Permutation!感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解Codeforces Round #436 (Div. 2) Make a Permutation!的各种细节,此外还有关于C. Diverse Permutation(Codeforces Round #275(div2)_html/css_WEB-ITnose、CF-Codeforces Round #485 (Div. 2)-E-Petr and Permutations、CodeCraft-19 and Codeforces Round #537 (Div. 2) A - Superhero Transformation、Codeforces 1082 A. Vasya and Book - 题意 (Educational Codeforces Round 55 (Rated for Div. 2))的实用技巧。

本文目录一览:

Codeforces Round #436 (Div. 2) Make a Permutation!

Codeforces Round #436 (Div. 2) Make a Permutation!

总结

以上是小编为你收集整理的Codeforces Round #436 (Div. 2) Make a Permutation!全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

C. Diverse Permutation(Codeforces Round #275(div2)_html/css_WEB-ITnose

C. Diverse Permutation(Codeforces Round #275(div2)_html/css_WEB-ITnose

C. Diverse Permutation

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

permutation p is an ordered set of integers p1,???p2,???...,???pn, consisting of n distinct positive integers not larger than n. we''ll denote as nthe length of permutation p1,???p2,???...,???pn.

Your task is to find such permutation p of length n, that the group of numbers |p1?-?p2|,?|p2?-?p3|,?...,?|pn?-?1?-?pn| has exactly k distinct elements.

Input

The single line of the input contains two space-separated positive integers n, k (1?≤?k?

Output

Print n integers forming the permutation. If there are multiple answers, print any of them.

Sample test(s)

input

3 2
登录后复制

output

1 3 2
登录后复制

input

3 1
登录后复制

output

1 2 3
登录后复制

input

5 2
登录后复制

output

1 3 2 4 5
登录后复制

Note

By |x| we denote the absolute value of number x.

立即学习“前端免费学习笔记(深入)”;

用n个数1~n,每个数只能用一次,组成差值的绝对值有k个数,为1~k。输出任一个方案。

构造题,我是这样构造的,取前k+1个数,第一个数取1,先+k,后一个数-(k-1),在后一个数+k-2.......这样从两头往

中间靠拢,既取完了k+1个数,又构造了1~k的差值绝对值,至于k+1后的嘛,每次+1就行了。

代码:

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int maxn=100000+1000;int ans[maxn];int main(){    int n,k;    ans[1]=1;    scanf("%d%d",&amp;n,&amp;k);    if(k==1)    {        for(int i=1;i   <br><br><p></p>   </cstring></algorithm></cstdio></iostream>
登录后复制

CF-Codeforces Round #485 (Div. 2)-E-Petr and Permutations

CF-Codeforces Round #485 (Div. 2)-E-Petr and Permutations

总结

以上是小编为你收集整理的CF-Codeforces Round #485 (Div. 2)-E-Petr and Permutations全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

CodeCraft-19 and Codeforces Round #537 (Div. 2) A - Superhero Transformation

CodeCraft-19 and Codeforces Round #537 (Div. 2) A - Superhero Transformation

题目描述

We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name ss can transform to another superhero with name tt if ss can be made equal to tt by changing any vowel in ss to any other vowel and any consonant in ss to any other consonant. Multiple changes can be made.

In this problem, we consider the letters ''a'', ''e'', ''i'', ''o'' and ''u'' to be vowels and all the other letters to be consonants.

Given the names of two superheroes, determine if the superhero with name ss can be transformed to the Superhero with name tt.

Input

The first line contains the string ss having length between 11 and 10001000, inclusive.

The second line contains the string tt having length between 11 and 10001000, inclusive.

Both strings ss and tt are guaranteed to be different and consist of lowercase English letters only.

Output

Output "Yes" (without quotes) if the superhero with name ss can be transformed to the superhero with name tt and "No" (without quotes) otherwise.

You can print each letter in any case (upper or lower).

Examples
input
a
u
output
Yes
input
abc
ukm
output
Yes
input
akm
ua
output
No
Note

In the first sample, since both ''a'' and ''u'' are vowels, it is possible to convert string ss to tt.

In the third sample, ''k'' is a consonant, whereas ''a'' is a vowel, so it is not possible to convert string ss to tt.

 

思路:签到题,就是元音和辅音相同位置的相同的话,输出 Yes,不同的话输出 No;

注意

strlen () 函数求出的字符串长度为有效长度,既不包含字符串末尾结束符 ‘\0’;
sizeof () 操作符求出的长度包含字符串末尾的结束符 ‘\0’;
当在函数内部使用 sizeof () 求解由函数的形参传入的字符数组的长度时,得到的结果为指针的长度,既对应变量的字节数,而不是字符串的长度,此处一定要小心。

 string 类的 size ()/length () 方法返回的是字节数,不管是否有汉字。

例:

string str="0123456789";
cout <<"str.length ()="<<str.length ()<<endl;// 结果为 10
cout <<"str.size ()="<<str.size ()<<endl;// 结果为 10

代码如下:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 
 5 int vow(char a,char b)
 6 {
 7     if(a == b)
 8     return 1;
 9     else if(a == ''a'' || a == ''o'' || a == ''e'' || a == ''i'' || a == ''u'')
10     {
11         if(b == ''a'' || b == ''o'' || b == ''e'' || b == ''i'' || b == ''u'')//元元
12         return 1;
13         else//元辅
14         return 0;
15     }
16     else if(b == ''a'' || b == ''o'' || b == ''e'' || b == ''i'' || b == ''u'')//辅元
17     return 0;
18     //辅辅
19     return 1;
20 }
21 int main()
22 {
23     string s,t;
24     while(cin >> s >> t)
25     {
26         int sl = s.size();
27         int tl = t.size();
28         if(sl != tl)
29         {
30             cout << "No" << endl;
31             continue;
32         }
33         bool flag = 0;
34         for(int i = 0;i < sl;i++)
35         {
36             if(vow(s[i],t[i]) == 0)
37             {
38                 cout << "No" << endl;
39                 flag = 1;
40                 break;
41             }
42         }
43         if(flag == 0)
44         cout << "Yes" << endl;
45     }
46     return 0;
47 }

 

Codeforces 1082 A. Vasya and Book - 题意 (Educational Codeforces Round 55 (Rated for Div. 2))

Codeforces 1082 A. Vasya and Book - 题意 (Educational Codeforces Round 55 (Rated for Div. 2))

A. Vasya and Book
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya is reading a e-book. The file of the book consists of nn pages, numbered from 11 to nn. The screen is currently displaying the contents of page xx, and Vasya wants to read the page yy. There are two buttons on the book which allow Vasya to scroll dd pages forwards or backwards (but he cannot scroll outside the book). For example, if the book consists of 1010 pages, and d=3d=3, then from the first page Vasya can scroll to the first or to the fourth page by pressing one of the buttons; from the second page — to the first or to the fifth; from the sixth page — to the third or to the ninth; from the eighth — to the fifth or to the tenth.

Help Vasya to calculate the minimum number of times he needs to press a button to move to page yy.

Input

The first line contains one integer tt (1t1031≤t≤103) — the number of testcases.

Each testcase is denoted by a line containing four integers nn, xx, yy, dd (1n,d1091≤n,d≤109, 1x,yn1≤x,y≤n) — the number of pages, the starting page, the desired page, and the number of pages scrolled by pressing one button, respectively.

Output

Print one line for each test.

If Vasya can move from page xx to page yy, print the minimum number of times he needs to press a button to do it. Otherwise print 1−1.

Example
input
Copy
3
10 4 5 2
5 1 3 4
20 4 19 3
output
Copy
4
-1
5
Note

In the first test case the optimal sequence is: 421354→2→1→3→5.

In the second test case it is possible to get to pages 11 and 55.

In the third test case the optimal sequence is: 47101316194→7→10→13→16→19.

 

 

 

翻到头只能从头翻,翻到尾只能从尾倒着翻。

 

代码:

 1 //A
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 typedef long long ll;
 5 const int maxn=1e5+10;
 6 const int inf=0x3f3f3f3f;
 7 
 8 int main()
 9 {
10     int t;
11     cin>>t;
12     while(t--){
13         int n,x,y,d,ans=inf;
14         cin>>n>>x>>y>>d;
15         if(abs(y-x)%d==0) {ans=min(ans,abs(y-x)/d);}
16         if((y-1)%d==0) {ans=min(ans,x/d+(y-1)/d+(x%d==0?0:1));}
17         if((n-y)%d==0) {ans=min(ans,(n-x)/d+(n-y)/d+((n-x)%d==0?0:1));}
18         if(ans==inf) cout<<-1<<endl;
19         else cout<<ans<<endl;
20     }
21 }

 

 

 

关于Codeforces Round #436 (Div. 2) Make a Permutation!的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于C. Diverse Permutation(Codeforces Round #275(div2)_html/css_WEB-ITnose、CF-Codeforces Round #485 (Div. 2)-E-Petr and Permutations、CodeCraft-19 and Codeforces Round #537 (Div. 2) A - Superhero Transformation、Codeforces 1082 A. Vasya and Book - 题意 (Educational Codeforces Round 55 (Rated for Div. 2))等相关内容,可以在本站寻找。

本文标签: