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
3b90ba5
commit 979b4b8
Showing
6 changed files
with
242 additions
and
61 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
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,20 @@ | ||
def readInts(): | ||
return list(map(int, input().split())) | ||
def readInt(): | ||
return int(input()) | ||
def readIntsindex0(): | ||
return list(map(lambda x: int(x) - 1, input().split())) | ||
|
||
|
||
n, k = readInts() | ||
a = readInts() | ||
|
||
best = -1 | ||
sel = -1 | ||
for i in range(k): | ||
cur = n - n % a[i] | ||
if best < cur: | ||
best = cur | ||
sel = i | ||
|
||
print('%d %d' % (sel + 1, n // a[sel])) |
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,30 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
const int mod=1e9+7; | ||
int po(int x,int k) | ||
{ | ||
int sum=1; | ||
while(k) | ||
{ | ||
if(k&1) | ||
{ | ||
sum=1LL*sum*x%mod; | ||
} | ||
x=1LL*x*x%mod; | ||
k>>=1; | ||
} | ||
return sum; | ||
} | ||
int main() | ||
{ | ||
int t; | ||
scanf("%d",&t); | ||
while(t--) | ||
{ | ||
int n,m; | ||
scanf("%d%d",&n,&m); | ||
printf("%d\n",1LL*po(n+1,m-1)*(n-m+1)%mod*po (2,m)%mod); | ||
} | ||
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import math | ||
import sys | ||
n=int(input()) | ||
mod = pow(10,9)+7 | ||
mod = 10000000007 | ||
ans =1 | ||
for i in range(n): | ||
p , m = map(int , raw_input().split()) | ||
ans1 = pow(2*(p+1) , m , mod)%mod | ||
ans2 = pow((p+1) , mod-2 , mod)%mod | ||
ans3 = (p+1-m)%mod | ||
n,m = map(int,raw_input().split()) | ||
ans1 = pow(2,m)%mod | ||
ans2 = pow(n+1,m-1)%mod | ||
ans3 = (n+1-m)%mod | ||
ans = (ans1*ans2*ans3)%mod | ||
# print(ans1,ans2,ans3) | ||
print(ans) |
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
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,90 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
const int MAX=400005; | ||
int timer,counter,n,m,disk[MAX],low[MAX],vis[MAX],scc[MAX]; | ||
stack<int> st; | ||
vector<int> adj[MAX]; | ||
int neg(int a){ return (a>n ? a-n : a+n); } | ||
void dfs_tarjan(int node){ | ||
disk[node]=low[node]=++timer; | ||
vis[node]=1; | ||
st.push(node); | ||
for(int child : adj[node]){ | ||
if(vis[child]==1){ | ||
low[node]=min(low[node],disk[child]); | ||
}else if(vis[child]==0){ | ||
dfs_tarjan(child); | ||
low[node]=min(low[node],low[child]); | ||
} | ||
} | ||
if(disk[node]==low[node]){ | ||
counter++; | ||
while(st.top()!=node){ | ||
scc[st.top()]=counter; | ||
vis[st.top()]=-1; | ||
st.pop(); | ||
} | ||
scc[st.top()]=counter; | ||
vis[st.top()]=-1; | ||
st.pop(); | ||
} | ||
} | ||
int main(){ | ||
int test,a,b,i; | ||
scanf("%d",&test); | ||
while(test--){ | ||
counter=timer=0; | ||
scanf("%d%d",&n,&m); | ||
for(i=1;i<=2*n;i++){ | ||
vis[i]=disk[i]=low[i]=scc[i]=0; | ||
adj[i].clear(); | ||
} | ||
for(i=1;i<=n;i++){ | ||
adj[neg(n+i)].push_back(i); | ||
adj[neg(i)].push_back(n+i); | ||
adj[n+i].push_back(neg(i)); | ||
adj[i].push_back(neg(n+i)); | ||
} | ||
for(i=1;i<=m;i++){ | ||
scanf("%d%d",&a,&b); | ||
adj[neg(a)].push_back(b); | ||
adj[neg(b)].push_back(a); | ||
} | ||
for(int node=1;node<=2*n;node++){ | ||
if(vis[node]==0) | ||
dfs_tarjan(node); | ||
} | ||
for(i=1;i<=n;i++){ | ||
if(scc[i]==scc[neg(i)]) | ||
break; | ||
} | ||
if(i<=n){ | ||
printf("boring\n"); | ||
}else{ | ||
printf("interesting\n"); | ||
} | ||
} | ||
return 0; | ||
} | ||
/* | ||
Input: | ||
2 | ||
2 6 | ||
3 1 | ||
1 4 | ||
2 4 | ||
2 3 | ||
4 3 | ||
2 1 | ||
4 4 | ||
1 3 | ||
2 4 | ||
5 7 | ||
6 8 | ||
Output: | ||
boring | ||
interesting | ||
*/ |