forked from harrypotter0/algorithms-in-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35c4f16
commit 7311e7f
Showing
3 changed files
with
164 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,36 @@ | ||
import re | ||
for _ in range(int(input())): | ||
n,m,x,k= map(int,raw_input().split()) | ||
string = raw_input() | ||
oddp,evenp = 0,0 | ||
for i in range(int(len(string))): | ||
if(string[i]=='O'): | ||
oddp+=1 | ||
else: | ||
evenp+=1 | ||
if(m*x<n or n>k): | ||
print("no") | ||
continue | ||
# if(m==1 and not(re.search('O',string))): | ||
# print("no") | ||
# continue | ||
# # print(re.search('O',string)) | ||
evenpm = m/2 | ||
oddpm = m%2 + m/2 | ||
evenp = (evenp/x)*x | ||
oddp = (oddp/x)*x | ||
e = min(evenp,evenpm*x) | ||
o = min(oddp,oddpm*x) | ||
# print(evenp,evenpm,oddp,oddpm,e,o) | ||
summ = e+o | ||
if(summ>=n): | ||
print("yes") | ||
else : | ||
print("no") | ||
def inp(): return input() | ||
|
||
def inpv(): return [int(x) for x in raw_input().split()] | ||
|
||
MOD = 10 ** 9 + 7 | ||
|
||
def chefptnt(): | ||
for _ in range(input()): | ||
n, m, x, k = map(int,raw_input().split()) | ||
s = raw_input().strip() | ||
ev = 0 | ||
for c in s: ev += c == 'E' | ||
odd = len(s) - ev | ||
mx = 0 | ||
for i in range(1,m+1): | ||
if i & 1: | ||
v = min(odd, x) | ||
odd -= v | ||
else: | ||
v = min(ev, x) | ||
ev -= v | ||
mx += v | ||
print 'yes' if mx >= n else 'no' | ||
|
||
chefptnt() | ||
|
||
|
||
''' | ||
3 | ||
4 4 2 4 | ||
EEOO | ||
4 3 1 4 | ||
EEOO | ||
6 4 2 6 | ||
EEEOOO | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* | ||
******************************************************************************************** | ||
* AUTHOR : harrypotter0 * | ||
* Language: C++14 * | ||
* Motto : The master has failed more times than the beginner has even tried. * * | ||
* IDE used: Atom * | ||
* My Domain : http://harrypotter.tech/ * | ||
******************************************************************************************** | ||
* | ||
*/ | ||
|
||
#include <iostream> | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main() { | ||
// your code goes here | ||
#ifdef JUDGE | ||
freopen("input.txt", "rt", stdin); | ||
freopen("output.txt", "wt", stdout); | ||
#endif | ||
ios_base::sync_with_stdio(0); | ||
cin.tie(NULL); | ||
cout.tie(NULL); | ||
int t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
string s; | ||
cin>>s; | ||
int n=s.length(); | ||
vector<int> ind[26]; | ||
int freq[26]={0}; | ||
int i; | ||
for(i=0;i<n;i++) | ||
{ | ||
freq[s[i]-'a']++; | ||
ind[s[i]-'a'].push_back(i); | ||
} | ||
int odd=0; | ||
for(i=0;i<26;i++) | ||
if(freq[i]&1) | ||
odd++; | ||
if(odd>1) | ||
{ | ||
cout<<-1<<endl; | ||
continue; | ||
} | ||
int ans[n]; | ||
for(i=0;i<n;i++)ans[i]=-1; | ||
int index=0; | ||
for(i=0;i<26;i++) | ||
{ | ||
int j=0; | ||
if(freq[i]&1)continue; | ||
for(j=0;j<freq[i]/2;j++) | ||
{ | ||
ans[index++]=ind[i][j]; | ||
ans[n-index]=ind[i][freq[i]-1-j]; | ||
} | ||
} | ||
char ch; | ||
for(i=0;i<26;i++) | ||
if(freq[i]&1) | ||
{ | ||
ch='a'+i; | ||
break; | ||
} | ||
int k=0; | ||
for(i=0;i<n;i++) | ||
if(ans[i]==-1)ans[i]=ind[ch-'a'][k++]; | ||
|
||
for(i=0;i<n;i++)cout<<ans[i]+1<<" ";cout<<endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* | ||
******************************************************************************************** | ||
* AUTHOR : harrypotter0 * | ||
* Language: C++14 * | ||
* Motto : The master has failed more times than the beginner has even tried. * * | ||
* IDE used: Atom * | ||
* My Domain : http://harrypotter.tech/ * | ||
******************************************************************************************** | ||
* | ||
*/ | ||
|
||
#include <iostream> | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
int main() { | ||
// your code goes here | ||
#ifdef JUDGE | ||
freopen("input.txt", "rt", stdin); | ||
freopen("output.txt", "wt", stdout); | ||
#endif | ||
ios_base::sync_with_stdio(0); | ||
cin.tie(NULL); | ||
cout.tie(NULL); | ||
int t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
int n,i; | ||
long double c,d,s; | ||
cin>>n; | ||
long double arr[n],sum=0; | ||
for(i=0;i<n;i++){cin>>arr[i];sum+=arr[i];} | ||
cin>>c>>d>>s; | ||
long double t1=sum,t2=0; | ||
long double wait[n]; | ||
wait[0]=arr[0]; | ||
long double totwait=0,zero=0,curr=0; | ||
totwait+=wait[0]; | ||
for(i=1;i<n;i++) | ||
{ | ||
wait[i]=arr[i]-arr[i-1]+ (wait[i-1]<0?wait[i-1]:0); | ||
totwait+=max(wait[i],zero); | ||
} | ||
cout<<fixed<<setprecision(10)<<(c-1)*totwait<<endl; | ||
} | ||
|
||
return 0; | ||
} |