Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
2016-10-02 13:52
337 查看
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进制的时钟,给你一个正确或者错误的时间表示,求你用最少的改变使它变成一个正确的时间。
题解:
分钟很好解决,如果大于59,输出0和它对10求余的数即可。对于小时数,如果是24进制的,小时数如果大于23,输出0和它对10求余的数即可,如果为12进制。如果它大于12或者为0,如果为10的倍数,输出10,不然输出0和它对10求余的数即可。
比赛时:XJB搞,pp了然后就被cha了,第一次被cha。。。
代码:
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 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
题意:就是给你n个数和n句话,问每句话里的元音字母的个数跟所给数是否相同,如果全部相同就输出YES。否则NO。
题解:水题,姿势优美即可,注意每句话可能有空格。
代码:
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个操作每次去除下标为I的数,问你剩下数的最大子序列为多少。
题解:离线操作,每次我们加入一个数,判断它左右是否存在数,如果存在,并查集连在一起,记录答案即可。
代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define ll __int64
ll ji[1000000];
ll b[1000000];
int vis[1000000];
int f[1000000];
ll output[1000000];
int find(int a)
{
int r=a;
while(f[r]!=r)
r=f[r];
int i=a;
int j;
while(i!=r)
{
j=f[i];
f[i]=r;
i=j;
}
return r;
}
void merge(int a,int b)
{
int A,B;
A=find(a);
B=find(b);
if(A!=B)
{
f[B]=A;
ji[A]+=ji[B];
}
}
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)f[i]=i;
for(int i=1;i<=n;i++)
{
scanf("%I64d",&ji[i]);
}
for(int i=1;i<=n;i++)
{
scanf("%I64d",&b[i]);
}
ll ans=0;
int contz=0;
for(int i=n;i>=1;i--)
{
output[contz++]=ans;
vis[b[i]]=1;
if(b[i]-1>=1&&vis[b[i]-1]==1)
{
merge(b[i],b[i]-1);
}
if(b[i]+1<=n&&vis[b[i]+1]==1)
{
merge(b[i],b[i]+1);
}
ans=max(ji[find(b[i])],ans);
}
for(int i=contz-1;i>=0;i--)
{
printf("%I64d\n",output[i]);
}
}
}
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进制的时钟,给你一个正确或者错误的时间表示,求你用最少的改变使它变成一个正确的时间。
题解:
分钟很好解决,如果大于59,输出0和它对10求余的数即可。对于小时数,如果是24进制的,小时数如果大于23,输出0和它对10求余的数即可,如果为12进制。如果它大于12或者为0,如果为10的倍数,输出10,不然输出0和它对10求余的数即可。
比赛时:XJB搞,pp了然后就被cha了,第一次被cha。。。
代码:
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c; scanf("%d",&c); scanf("%d:%d",&a,&b); if(c==12) { if(a>12||!a) { if(a%10==0) printf("10"); else printf("0%d",a%10); } else { printf("%02d",a); } printf(":"); if(b>59) printf("0%d",b%10); else printf("%02d",b); } else { if(a>23) printf("0%d",a%10); else printf("%02d",a); printf(":"); if(b>59) printf("0%d",b%10); else printf("%02d",b); } printf("\n"); return 0; }
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 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
题意:就是给你n个数和n句话,问每句话里的元音字母的个数跟所给数是否相同,如果全部相同就输出YES。否则NO。
题解:水题,姿势优美即可,注意每句话可能有空格。
代码:
#include <bits/stdc++.h> using namespace std; int a[120]; char s[120]; int main() { int t; scanf("%d",&t); for(int i=1;i<=t;i++) { scanf("%d",&a[i]); } int flag=1; getchar(); for(int i=1;i<=t;i++) { int ans=0; gets(s); int len=strlen(s); for(int j=0;j<len;j++) { if(s[j]=='a'||s[j]=='e'||s[j]=='i'||s[j]=='o'||s[j]=='u'||s[j]=='y') ans++; } if(ans!=a[i]) { flag=0; } } if(flag) { cout<<"YES"<<endl; } else { cout<<"NO"<<endl; } }
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个操作每次去除下标为I的数,问你剩下数的最大子序列为多少。
题解:离线操作,每次我们加入一个数,判断它左右是否存在数,如果存在,并查集连在一起,记录答案即可。
代码:
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define ll __int64
ll ji[1000000];
ll b[1000000];
int vis[1000000];
int f[1000000];
ll output[1000000];
int find(int a)
{
int r=a;
while(f[r]!=r)
r=f[r];
int i=a;
int j;
while(i!=r)
{
j=f[i];
f[i]=r;
i=j;
}
return r;
}
void merge(int a,int b)
{
int A,B;
A=find(a);
B=find(b);
if(A!=B)
{
f[B]=A;
ji[A]+=ji[B];
}
}
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)f[i]=i;
for(int i=1;i<=n;i++)
{
scanf("%I64d",&ji[i]);
}
for(int i=1;i<=n;i++)
{
scanf("%I64d",&b[i]);
}
ll ans=0;
int contz=0;
for(int i=n;i>=1;i--)
{
output[contz++]=ans;
vis[b[i]]=1;
if(b[i]-1>=1&&vis[b[i]-1]==1)
{
merge(b[i],b[i]-1);
}
if(b[i]+1<=n&&vis[b[i]+1]==1)
{
merge(b[i],b[i]+1);
}
ans=max(ji[find(b[i])],ans);
}
for(int i=contz-1;i>=0;i--)
{
printf("%I64d\n",output[i]);
}
}
}
相关文章推荐
- Codeforces Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) 部分题解
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)E. Research Rover (容斥Lucas)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- A. Broken Clock (贪心)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- B. Verse Pattern(水题)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) -- D. Generating Sets(贪心)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C 并查集
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)F. Cyclic Cipher
- codeforces(Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) )(C,D)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)C. Destroying Array(想法题/并查集)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array(并查集)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A. Broken Clock 水题
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)C. Destroying Array(想法题/并查集)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) B. Verse Pattern 水题
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)D. Generating Sets(贪心)
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) F
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) C. Destroying Array 带权并查集
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) E
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D. Generating Sets 贪心
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)