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.
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.
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.
24
17:30
17:30
12
17:30
07:30
24
99:99
09:09
题意:12/24计时方法下 对于非法的时间 更改最少的位数 使得合法并输出
题解:水
注意数据
12
30:00
1 /****************************** 2 code by drizzle 3 blog: www.cnblogs.com/hsd-/ 4 ^ ^ ^ ^ 5 O O 6 ******************************/ 7 #include<bits/stdc++.h> 8 #include<map> 9 #include<set> 10 #include<cmath> 11 #include<queue> 12 #include<bitset> 13 #include<math.h> 14 #include<vector> 15 #include<string> 16 #include<stdio.h> 17 #include<cstring> 18 #include<iostream> 19 #include<algorithm> 20 #pragma comment(linker, "/STACK:102400000,102400000") 21 using namespace std; 22 #define A first 23 #define B second 24 const int mod=1000000007; 25 const int MOD1=1000000007; 26 const int MOD2=1000000009; 27 const double EPS=0.00000001; 28 //typedef long long ll; 29 typedef __int64 ll; 30 const ll MOD=1000000007; 31 const int INF=1000000010; 32 const ll MAX=1ll<<55; 33 const double eps=1e-5; 34 const double inf=~0u>>1; 35 const double pi=acos(-1.0); 36 typedef double db; 37 typedef unsigned int uint; 38 typedef unsigned long long ull; 39 int what; 40 char a[10]; 41 int main() 42 { 43 scanf("%d",&what); 44 getchar(); 45 scanf("%s",a); 46 if(what==24) 47 { 48 int s,t; 49 s=(a[0]-'0')*10+(a[1]-'0'); 50 t=(a[3]-'0')*10+(a[4]-'0'); 51 //cout<<s<<" "<<t<<endl; 52 if(s>23) 53 a[0]='0'; 54 if(t>59) 55 a[3]='0'; 56 } 57 else 58 { 59 int s,t; 60 s=(a[0]-'0')*10+a[1]-'0'; 61 t=(a[3]-'0')*10+a[4]-'0'; 62 if(s==0) 63 a[0]='1'; 64 if(s>12) 65 { 66 if(a[1]=='0') 67 a[0]='1'; 68 else 69 a[0]='0'; 70 } 71 if(t>59) 72 a[3]='0'; 73 } 74 cout<<a<<endl; 75 return 0; 76 }
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.
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.
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).
3
2 2 3
intel
code
ch allenge
YES
4
1 2 3 1
a
bcdefghi
jklmnopqrstu
vwxyz
NO
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
YES
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
题解:模拟
1 /****************************** 2 code by drizzle 3 blog: www.cnblogs.com/hsd-/ 4 ^ ^ ^ ^ 5 O O 6 ******************************/ 7 #include<bits/stdc++.h> 8 #include<map> 9 #include<set> 10 #include<cmath> 11 #include<queue> 12 #include<bitset> 13 #include<math.h> 14 #include<vector> 15 #include<string> 16 #include<stdio.h> 17 #include<cstring> 18 #include<iostream> 19 #include<algorithm> 20 #pragma comment(linker, "/STACK:102400000,102400000") 21 using namespace std; 22 #define A first 23 #define B second 24 const int mod=1000000007; 25 const int MOD1=1000000007; 26 const int MOD2=1000000009; 27 const double EPS=0.00000001; 28 //typedef long long ll; 29 typedef __int64 ll; 30 const ll MOD=1000000007; 31 const int INF=1000000010; 32 const ll MAX=1ll<<55; 33 const double eps=1e-5; 34 const double inf=~0u>>1; 35 const double pi=acos(-1.0); 36 typedef double db; 37 typedef unsigned int uint; 38 typedef unsigned long long ull; 39 int n; 40 int a[105]; 41 char b[105][105]; 42 map<char,int>mp; 43 int main() 44 { 45 mp['a']=1; 46 mp['e']=1; 47 mp['i']=1; 48 mp['o']=1; 49 mp['u']=1; 50 mp['y']=1; 51 scanf("%d",&n); 52 int flag=0; 53 memset(b,0,sizeof(b)); 54 for(int i=1;i<=n;i++) 55 scanf("%d",&a[i]); 56 getchar(); 57 for(int i=1;i<=n;i++) 58 { 59 gets(b[i]); 60 int ans=0; 61 int len=strlen(b[i]); 62 for(int j=0;j<len;j++) 63 { 64 if(mp[b[i][j]]) 65 ans++; 66 } 67 if(ans!=a[i]) 68 flag=1; 69 } 70 if(flag) 71 cout<<"NO"<<endl; 72 else 73 cout<<"YES"<<endl; 74 return 0; 75 }
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.
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.
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.
4
1 3 2 5
3 4 1 2
5
4
3
0
5
1 2 3 4 5
4 2 3 5 1
6
5
5
1
0
8
5 5 4 4 6 6 5 5
5 2 8 7 1 3 4 6
18
16
11
8
8
6
6
0
Consider the first sample:
- Third element is destroyed. Array is now 1 3 * 5. Segment with maximum sum 5 consists of one integer 5.
- Fourth element is destroyed. Array is now 1 3 * * . Segment with maximum sum 4 consists of two integers 1 3.
- First element is destroyed. Array is now * 3 * * . Segment with maximum sum 3 consists of one integer 3.
- 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输出 并查集处理
1 /****************************** 2 code by drizzle 3 blog: www.cnblogs.com/hsd-/ 4 ^ ^ ^ ^ 5 O O 6 ******************************/ 7 #include<bits/stdc++.h> 8 #include<map> 9 #include<set> 10 #include<cmath> 11 #include<queue> 12 #include<bitset> 13 #include<math.h> 14 #include<vector> 15 #include<string> 16 #include<stdio.h> 17 #include<cstring> 18 #include<iostream> 19 #include<algorithm> 20 #pragma comment(linker, "/STACK:102400000,102400000") 21 using namespace std; 22 #define A first 23 #define B second 24 const int mod=1000000007; 25 const int MOD1=1000000007; 26 const int MOD2=1000000009; 27 const double EPS=0.00000001; 28 //typedef long long ll; 29 typedef __int64 ll; 30 const ll MOD=1000000007; 31 const int INF=1000000010; 32 const ll MAX=1ll<<55; 33 const double eps=1e-5; 34 const double inf=~0u>>1; 35 const double pi=acos(-1.0); 36 typedef double db; 37 typedef unsigned int uint; 38 typedef unsigned long long ull; 39 int n; 40 ll a[100005]; 41 ll s[100005]; 42 int used[100005]; 43 int pos[100005]; 44 int fa[100005]; 45 ll re[100005]; 46 int find(int root) 47 { 48 if(fa[root]!=root) 49 fa[root]=find(fa[root]); 50 return fa[root]; 51 } 52 void uni(int a,int b) 53 { 54 int aa=find(a); 55 int bb=find(b); 56 if(aa!=bb) 57 { 58 fa[aa]=bb; 59 s[bb]+=s[aa]; 60 } 61 } 62 int main() 63 { 64 scanf("%d",&n); 65 for(int i=1; i<=n; i++) 66 { 67 scanf("%I64d",&a[i]); 68 fa[i]=i; 69 } 70 for(int i=1; i<=n; i++) 71 scanf("%d",&pos[i]); 72 ll ans=0; 73 for(int i=n; i>=1; i--) 74 { 75 s[pos[i]]=a[pos[i]]; 76 used[pos[i]]=1; 77 if(pos[i]<n&&used[pos[i]+1]) 78 uni(pos[i],pos[i]+1); 79 if(pos[i]>1&&used[pos[i]-1]) 80 uni(pos[i],pos[i]-1); 81 re[i]=ans; 82 ans=max(ans,s[find(pos[i])]); 83 } 84 for(int i=1; i<=n; i++) 85 printf("%I64d ",re[i]); 86 return 0; 87 }
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:
- Take any integer xi and multiply it by two, i.e. replace xi with 2·xi.
- 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.
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.
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.
5
1 2 3 4 5
4 5 2 3 1
6
15 14 3 13 1 12
12 13 14 7 3 1
6
9 7 13 17 5 11
4 5 2 6 3 1
题意:给你集合y 要求集合x x,y中的元素的都是不同的 集合x可以通过集合内的元素xi不断更新为2*xi或2*xi+1 同一个x只能变为y中的一个数 从而获得集合y
输出满足条件的集合x 要求x的最大值尽量小
题解:优先队列处理
1 /****************************** 2 code by drizzle 3 blog: www.cnblogs.com/hsd-/ 4 ^ ^ ^ ^ 5 O O 6 ******************************/ 7 #include<bits/stdc++.h> 8 #include<map> 9 #include<set> 10 #include<cmath> 11 #include<queue> 12 #include<bitset> 13 #include<math.h> 14 #include<vector> 15 #include<string> 16 #include<stdio.h> 17 #include<cstring> 18 #include<iostream> 19 #include<algorithm> 20 #pragma comment(linker, "/STACK:102400000,102400000") 21 using namespace std; 22 #define A first 23 #define B second 24 const int mod=1000000007; 25 const int MOD1=1000000007; 26 const int MOD2=1000000009; 27 const double EPS=0.00000001; 28 //typedef long long ll; 29 typedef __int64 ll; 30 const ll MOD=1000000007; 31 const int INF=1000000010; 32 const ll MAX=1ll<<55; 33 const double eps=1e-5; 34 const double inf=~0u>>1; 35 const double pi=acos(-1.0); 36 typedef double db; 37 typedef unsigned int uint; 38 typedef unsigned long long ull; 39 int n; 40 ll a[50004]; 41 map<ll,int> mp; 42 ll ans[50004]; 43 ll exm; 44 struct node 45 { 46 ll we; 47 friend bool operator < (struct node aa, struct node bb) 48 { 49 return aa.we < bb.we; 50 } 51 } now; 52 priority_queue<node> pq; 53 int main() 54 { 55 scanf("%d",&n); 56 for(int i=1; i<=n; i++) 57 { 58 scanf("%I64d",&a[i]); 59 mp[a[i]]=1; 60 now.we=a[i]; 61 pq.push(now); 62 } 63 int jishu=0; 64 while(!pq.empty()) 65 { 66 now=pq.top(); 67 pq.pop(); 68 ll num=now.we; 69 while(num) 70 { 71 if(mp[num]==0) 72 break; 73 num=num>>1; 74 } 75 if(num&&mp[num]==0) 76 { 77 node gg; 78 gg.we=num; 79 pq.push(gg); 80 mp[now.we]=0; 81 mp[num]=1; 82 } 83 else 84 ans[jishu++]=now.we; 85 } 86 for(int i=0; i<n; i++) 87 printf("%I64d ",ans[i]); 88 printf(" "); 89 return 0; 90 }