A. Broken Clock
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.

You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.

For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.

Input

The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.

The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.

Output

The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.

Examples
Input
24
17:30
Output
17:30
Input
12
17:30
Output
07:30
Input
24
99:99
Output
09:09
题意:12/24计时方法下 对于非法的时间 更改最少的位数 使得合法并输出
题解:水
注意数据
12
30:00
 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
//typedef long long ll;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
int what;
char a[];
int main()
{
scanf("%d",&what);
getchar();
scanf("%s",a);
if(what==)
{
int s,t;
s=(a[]-'')*+(a[]-'');
t=(a[]-'')*+(a[]-'');
//cout<<s<<" "<<t<<endl;
if(s>)
a[]='';
if(t>)
a[]='';
}
else
{
int s,t;
s=(a[]-'')*+a[]-'';
t=(a[]-'')*+a[]-'';
if(s==)
a[]='';
if(s>)
{
if(a[]=='')
a[]='';
else
a[]='';
}
if(t>)
a[]='';
}
cout<<a<<endl;
return ;
}
B. Verse Pattern
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.

We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'.

Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored.

The verse patterns for the given text is a sequence of n integers p1, p2, ..., pn. Text matches the given verse pattern if for each i from 1 to n one can divide words of the i-th line in syllables in such a way that the total number of syllables is equal to pi.

You are given the text and the verse pattern. Check, if the given text matches the given verse pattern.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of lines in the text.

The second line contains integers p1, ..., pn (0 ≤ pi ≤ 100) — the verse pattern.

Next n lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters.

Output

If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).

Examples
Input
3
2 2 3
intel
code
ch allenge
Output
YES
Input
4
1 2 3 1
a
bcdefghi
jklmnopqrstu
vwxyz
Output
NO
Input
4
13 11 15 15
to be or not to be that is the question
whether tis nobler in the mind to suffer
the slings and arrows of outrageous fortune
or to take arms against a sea of troubles
Output
YES
Note

In the first sample, one can split words into syllables in the following way:

in-tel
co-de
ch al-len-ge

Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one.

题意:统计aeiouy的个数 一 一对应则输出YES 否则输出NO

题解:模拟

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
//typedef long long ll;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
int n;
int a[];
char b[][];
map<char,int>mp;
int main()
{
mp['a']=;
mp['e']=;
mp['i']=;
mp['o']=;
mp['u']=;
mp['y']=;
scanf("%d",&n);
int flag=;
memset(b,,sizeof(b));
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
getchar();
for(int i=;i<=n;i++)
{
gets(b[i]);
int ans=;
int len=strlen(b[i]);
for(int j=;j<len;j++)
{
if(mp[b[i][j]])
ans++;
}
if(ans!=a[i])
flag=;
}
if(flag)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
return ;
}
C. Destroying Array
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array consisting of n non-negative integers a1, a2, ..., an.

You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array are destroyed.

After each element is destroyed you have to find out the segment of the array, such that it contains no destroyed elements and the sum of its elements is maximum possible. The sum of elements in the empty segment is considered to be 0.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the length of the array.

The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).

The third line contains a permutation of integers from 1 to n — the order used to destroy elements.

Output

Print n lines. The i-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first i operations are performed.

Examples
Input
4
1 3 2 5
3 4 1 2
Output
5
4
3
0
Input
5
1 2 3 4 5
4 2 3 5 1
Output
6
5
5
1
0
Input
8
5 5 4 4 6 6 5 5
5 2 8 7 1 3 4 6
Output
18
16
11
8
8
6
6
0
Note

Consider the first sample:

  1. Third element is destroyed. Array is now 1 3  *  5. Segment with maximum sum 5 consists of one integer 5.
  2. Fourth element is destroyed. Array is now 1 3  *   * . Segment with maximum sum 4 consists of two integers 1 3.
  3. First element is destroyed. Array is now  *  3  *   * . Segment with maximum sum 3 consists of one integer 3.
  4. Last element is destroyed. At this moment there are no valid nonempty segments left in this array, so the answer is equal to 0.

题意:给你n个数 并给出删除这n个数的次序 对于每次删除 输出连续区间(不包括删除的位置的数)的和的最大值

题解:逆向来思考 正向的删除 当作逆向的增加 每增加一个数 判断是否与已知的集合相邻 或者作为新的集合 取max输出 并查集处理

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
//typedef long long ll;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
int n;
ll a[];
ll s[];
int used[];
int pos[];
int fa[];
ll re[];
int find(int root)
{
if(fa[root]!=root)
fa[root]=find(fa[root]);
return fa[root];
}
void uni(int a,int b)
{
int aa=find(a);
int bb=find(b);
if(aa!=bb)
{
fa[aa]=bb;
s[bb]+=s[aa];
}
}
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%I64d",&a[i]);
fa[i]=i;
}
for(int i=; i<=n; i++)
scanf("%d",&pos[i]);
ll ans=;
for(int i=n; i>=; i--)
{
s[pos[i]]=a[pos[i]];
used[pos[i]]=;
if(pos[i]<n&&used[pos[i]+])
uni(pos[i],pos[i]+);
if(pos[i]>&&used[pos[i]-])
uni(pos[i],pos[i]-);
re[i]=ans;
ans=max(ans,s[find(pos[i])]);
}
for(int i=; i<=n; i++)
printf("%I64d\n",re[i]);
return ;
}
D. Generating Sets
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a set Y of n distinct positive integers y1, y2, ..., yn.

Set X of n distinct positive integers x1, x2, ..., xn is said to generate set Y if one can transform X to Y by applying some number of the following two operation to integers in X:

  1. Take any integer xi and multiply it by two, i.e. replace xi with 2·xi.
  2. Take any integer xi, multiply it by two and add one, i.e. replace xi with 2·xi + 1.

Note that integers in X are not required to be distinct after each operation.

Two sets of distinct integers X and Y are equal if they are equal as sets. In other words, if we write elements of the sets in the array in the increasing order, these arrays would be equal.

Note, that any set of integers (or its permutation) generates itself.

You are given a set Y and have to find a set X that generates Y and the maximum element of X is mininum possible.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 50 000) — the number of elements in Y.

The second line contains n integers y1, ..., yn (1 ≤ yi ≤ 109), that are guaranteed to be distinct.

Output

Print n integers — set of distinct integers that generate Y and the maximum element of which is minimum possible. If there are several such sets, print any of them.

Examples
Input
5
1 2 3 4 5
Output
4 5 2 3 1 
Input
6
15 14 3 13 1 12
Output
12 13 14 7 3 1 
Input
6
9 7 13 17 5 11
Output
4 5 2 6 3 1 

题意:给你集合y 要求集合x  x,y中的元素的都是不同的  集合x可以通过集合内的元素xi不断更新为2*xi或2*xi+1 同一个x只能变为y中的一个数 从而获得集合y
输出满足条件的集合x 要求x的最大值尽量小
题解:优先队列处理
 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
#define A first
#define B second
const int mod=;
const int MOD1=;
const int MOD2=;
const double EPS=0.00000001;
//typedef long long ll;
typedef __int64 ll;
const ll MOD=;
const int INF=;
const ll MAX=1ll<<;
const double eps=1e-;
const double inf=~0u>>;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
int n;
ll a[];
map<ll,int> mp;
ll ans[];
ll exm;
struct node
{
ll we;
friend bool operator < (struct node aa, struct node bb)
{
return aa.we < bb.we;
}
} now;
priority_queue<node> pq;
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%I64d",&a[i]);
mp[a[i]]=;
now.we=a[i];
pq.push(now);
}
int jishu=;
while(!pq.empty())
{
now=pq.top();
pq.pop();
ll num=now.we;
while(num)
{
if(mp[num]==)
break;
num=num>>;
}
if(num&&mp[num]==)
{
node gg;
gg.we=num;
pq.push(gg);
mp[now.we]=;
mp[num]=;
}
else
ans[jishu++]=now.we;
}
for(int i=; i<n; i++)
printf("%I64d ",ans[i]);
printf("\n");
return ;
}

Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列的更多相关文章

  1. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) B. Verse Pattern 水题

    B. Verse Pattern 题目连接: http://codeforces.com/contest/722/problem/B Description You are given a text ...

  2. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)

    A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  3. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)(set容器里count函数以及加强for循环)

    题目链接:http://codeforces.com/contest/722/problem/D 1 #include <bits/stdc++.h> #include <iostr ...

  4. 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D

    http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ...

  5. 线段树 或者 并查集 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C

    http://codeforces.com/contest/722/problem/C 题目大意:给你一个串,每次删除串中的一个pos,问剩下的串中,连续的最大和是多少. 思路一:正方向考虑问题,那么 ...

  6. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心

    D. Generating Sets 题目连接: http://codeforces.com/contest/722/problem/D Description You are given a set ...

  7. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array 带权并查集

    C. Destroying Array 题目连接: http://codeforces.com/contest/722/problem/C Description You are given an a ...

  8. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A. Broken Clock 水题

    A. Broken Clock 题目连接: http://codeforces.com/contest/722/problem/A Description You are given a broken ...

  9. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array

    C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. js基础之arguments、css

    arguments就是一个包含传入的参数的数组对象 栗子一: function sum(){ var result=0; for(var i=0;i<arguments.length;i++){ ...

  2. 类成员函数作为pthread_create函数参数

    from:http://www.cnblogs.com/shijingxiang/articles/5389294.html 近日需要将线程池封装成C++类,类名为Threadpool.在类的成员函数 ...

  3. ROS创建工作空间(三)

    查看正在使用的ROS工作空间,使用命令 echo $ROS_PACKAGE_PATH 我新建了两个

  4. 过滤器 Filter

    Filter(过滤器)简介 Filter 的基本功能是对发送到 Servlet 的请求进行拦截, 并对响应也进行拦截. Filter 程序是一个实现了 Filter 接口的 Java 类,与 Serv ...

  5. Problem A CodeForces 556A

    Description Andrewid the Android is a galaxy-famous detective. In his free time he likes to think ab ...

  6. shell变量的使用

    转载请标明http://www.cnblogs.com/winifred-tang94/ shell环境中变量有三种类型: a.  环境变量:可以在shell脚本中直接利用“$环境变量名称”的形式引用 ...

  7. data属性

    本框架内置组件以及部分插件可以通过data属性来初始化并使用,通常通过data-toggle来调用API(toggle是触发器的意思,例如我们创建一个navtab标签可以通过为a的data-toggl ...

  8. SVN服务器配置实战

    [需求] 为公司多个部门建立的SVN仓库compay 公司部门和人员构成 A部门 (zhangsan,lisi,wanger,mazi) B部门(jia,yi,bing,ding) C部门(chun, ...

  9. Mac下SVN服务器环境的搭建和配置(除展示图片外,所有命令在Linux/Unix下适用)

    这几天领导没有安排工作,闲着没事就想把自己这两年做iOS开发时感觉知识有欠缺的地方想好好深入地补习一下,昨天和今天就计划好好学习下SVN和git的从创建和到原理,到命令,到界面的使用.一不小心被另一领 ...

  10. kali linux SET工具包

    尝试使用SET生成Teensy脚本是出现问题 1.出现错误 [!] Something went wrong, printing the error: [Errno 2] No such file o ...