-
Notifications
You must be signed in to change notification settings - Fork 10
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
b7686a2
commit ffefe5f
Showing
34 changed files
with
2,058 additions
and
45 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "bits/stdc++.h" | ||
using namespace std; | ||
|
||
# define s(n) scanf("%d",&n) | ||
# define sc(n) scanf("%c",&n) | ||
# define sl(n) scanf("%lld",&n) | ||
# define sf(n) scanf("%lf",&n) | ||
# define ss(n) scanf("%s",n) | ||
|
||
#define R(i,n) for(int i=0;i<(n);i++) | ||
#define FOR(i,a,b) for(int i=(a);i<=(b);i++) | ||
#define FORD(i,a,b) for(int i=(a);i>=(b);i--) | ||
|
||
# define INF (int)1e9 | ||
# define EPS 1e-9 | ||
# define MOD 1000000007 | ||
|
||
|
||
typedef long long ll; | ||
|
||
int main() | ||
{ | ||
int t; | ||
cin >> t; | ||
while(t--){ | ||
int n; | ||
s(n); | ||
int a[n]; | ||
R(i,n){ | ||
s(a[i]); | ||
} | ||
sort(a,a+n); | ||
int coun=1,j=0,coun2=1; | ||
for(int i=n-1;i>0;i--){ | ||
if(a[i]==a[i-1]) | ||
coun++; | ||
else{ | ||
j=i; | ||
break; | ||
} | ||
} | ||
if(j==n-1){ | ||
for(int i=n-2;i>0;i--){ | ||
if(a[i]==a[i-1]) | ||
coun2++; | ||
else | ||
break; | ||
} | ||
} | ||
double ans=0; | ||
if(coun!=1){ | ||
ans= (double) (coun*(coun-1))/(double)(n*(n-1)); | ||
} else { | ||
ans = (double) 2*(coun2)/(double) (n*(n-1)); | ||
} | ||
printf("%lf\n",ans ); | ||
} | ||
|
||
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,117 @@ | ||
#include "bits/stdc++.h" | ||
using namespace std; | ||
|
||
# define s(n) scanf("%d",&n) | ||
# define sc(n) scanf("%c",&n) | ||
# define sl(n) scanf("%lld",&n) | ||
# define sf(n) scanf("%lf",&n) | ||
# define ss(n) scanf("%s",n) | ||
|
||
#define R(i,n) for(int i=0;i<(n);i++) | ||
#define FOR(i,a,b) for(int i=(a);i<=(b);i++) | ||
#define FORD(i,a,b) for(int i=(a);i>=(b);i--) | ||
|
||
# define INF (int)1e9 | ||
# define EPS 1e-9 | ||
# define MOD 1000000007 | ||
|
||
|
||
typedef long long ll; | ||
|
||
typedef struct node { | ||
ll val; | ||
int pos_i; | ||
int pos_j; | ||
}node; | ||
|
||
int g_count; | ||
bool compare(const node &a, const node &b) | ||
{ | ||
return a.val > b.val; | ||
} | ||
|
||
void traverse(bool **b,int m,int n, ll **a,int i,int j) { | ||
if(i-1>=0 && !b[i-1][j] ) { | ||
if(a[i][j]>=a[i-1][j]){ | ||
b[i-1][j]=true; | ||
g_count++; | ||
traverse(b,m,n,a,i-1,j); | ||
} | ||
} | ||
if(j-1>=0 && !b[i][j-1] ) { | ||
if(a[i][j]>=a[i][j-1]){ | ||
b[i][j-1]=true; | ||
g_count++; | ||
traverse(b,m,n,a,i,j-1); | ||
} | ||
} | ||
if(i+1<n && !b[i+1][j] ) { | ||
if(a[i][j]>=a[i+1][j]){ | ||
b[i+1][j]=true; | ||
g_count++; | ||
traverse(b,m,n,a,i+1,j); | ||
} | ||
} | ||
if(j+1< m && !b[i][j+1] ) { | ||
if(a[i][j]>=a[i][j+1]){ | ||
b[i][j+1]=true; | ||
g_count++; | ||
traverse(b,m,n,a,i,j+1); | ||
} | ||
} | ||
return; | ||
} | ||
|
||
int main() | ||
{ | ||
int t; | ||
cin >> t; | ||
while(t--){ | ||
int n,m; | ||
g_count=0; | ||
s(n);s(m); | ||
ll **a = (ll**) calloc(n,sizeof(ll*)); | ||
R(i,n){ | ||
a[i]=(ll*) calloc(m,sizeof(ll)); | ||
} | ||
vector<node> v; | ||
node v1; | ||
int ans=0; | ||
//bool b[n][m]; | ||
bool ** b =(bool **) calloc(n,sizeof(bool*)); | ||
R(i,n){ | ||
b[i]= (bool *) calloc(m,sizeof(bool)); | ||
} | ||
R(i,n){ | ||
R(j,m){ | ||
b[i][j]=false; | ||
sl(a[i][j]); | ||
v1.val=a[i][j]; | ||
v1.pos_j=j; | ||
v1.pos_i=i; | ||
v.push_back(v1); | ||
} | ||
} | ||
|
||
sort(v.begin(),v.end(),compare); | ||
R(i,v.size()){ | ||
if(g_count==m*n) | ||
break; | ||
if(!b[v[i].pos_i][v[i].pos_j]){ | ||
ans++; | ||
b[v[i].pos_i][v[i].pos_j]=true; | ||
traverse(b,m,n,a,v[i].pos_i,v[i].pos_j); | ||
} | ||
} | ||
|
||
printf("%d\n", ans ); | ||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
|
||
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,97 @@ | ||
#include "bits/stdc++.h" | ||
using namespace std; | ||
|
||
# define s(n) scanf("%d",&n) | ||
# define sc(n) scanf("%c",&n) | ||
# define sl(n) scanf("%lld",&n) | ||
# define sf(n) scanf("%lf",&n) | ||
# define ss(n) scanf("%s",n) | ||
|
||
#define R(i,n) for(int i=0;i<(n);i++) | ||
#define FOR(i,a,b) for(int i=(a);i<=(b);i++) | ||
#define FORD(i,a,b) for(int i=(a);i>=(b);i--) | ||
|
||
# define INF (int)1e9 | ||
# define EPS 1e-9 | ||
# define MOD 1000000007 | ||
|
||
|
||
typedef long long ll; | ||
|
||
typedef struct player | ||
{ | ||
int rank; | ||
int rating; | ||
int max_rating; | ||
bool rated; | ||
int min_rating; | ||
int time; | ||
char color; | ||
bool find; | ||
int match; | ||
} player; | ||
|
||
bool compare(const player &a, const player &b) | ||
{ | ||
if(a.rating < b.rating) | ||
return true; | ||
else if(a.rating == b.rating){ | ||
return a.max_rating < b.max_rating; | ||
} else | ||
return false; | ||
} | ||
|
||
int main() | ||
{ | ||
int t; | ||
cin >> t; | ||
while(t--){ | ||
int n; | ||
vector<player> v; | ||
player v1; | ||
s(n); | ||
string rated; | ||
string color; | ||
R(i,n){ | ||
v1.rank=i+1; | ||
s(v1.rating); s(v1.min_rating);s(v1.max_rating); | ||
s(v1.time); | ||
cin >> rated; | ||
cin >> color; | ||
v1.find=true; | ||
v1.match=-1; | ||
v1.color = color[0]; | ||
if(rated[0]=='u'){ | ||
v1.rated=false; | ||
} else | ||
v1.rated=true; | ||
v.push_back(v1); | ||
} | ||
//sort(v_rated.begin(),v_rated.end(),compare); | ||
// sort(v_unrated.begin(), v_unrated.end(),compare); | ||
R(i,(int)v.size()){ | ||
// printf("%d %d\n",v[i].rank,v[i].match ); | ||
for(int j=0;j<i;j++){ | ||
if(v[j].find){ | ||
//printf("%d %d\n",v[i].rank,j ); | ||
if(v[j].rated == v[i].rated && v[i].time == v[j].time && v[j].rating <= v[i].max_rating && v[j].rating >= v[i].min_rating && v[i].rating <=v[j].max_rating && v[i].rating >= v[j].min_rating && ((v[j].color=='r' && v[i].color=='r') || (v[j].color=='w' && v[i].color=='b')|| (v[j].color=='b' && v[i].color=='w'))){ | ||
v[i].find=false; | ||
v[j].find=false; | ||
v[i].match=v[j].rank; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
R(i,v.size()){ | ||
if(v[i].match==-1){ | ||
printf("wait\n"); | ||
} else{ | ||
printf("%d\n", v[i].match ); | ||
} | ||
} | ||
|
||
} | ||
|
||
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,76 @@ | ||
#include "bits/stdc++.h" | ||
#include <unordered_map> | ||
using namespace std; | ||
|
||
# define s(n) scanf("%d",&n) | ||
# define sc(n) scanf("%c",&n) | ||
# define sl(n) scanf("%lld",&n) | ||
# define sf(n) scanf("%lf",&n) | ||
# define ss(n) scanf("%s",n) | ||
|
||
#define R(i,n) for(int i=0;i<(n);i++) | ||
#define FOR(i,a,b) for(int i=(a);i<=(b);i++) | ||
#define FORD(i,a,b) for(int i=(a);i>=(b);i--) | ||
|
||
# define INF (int)1e9 | ||
# define EPS 1e-9 | ||
# define MOD 1000000007 | ||
|
||
|
||
typedef long long ll; | ||
|
||
int main() | ||
{ | ||
ll n,q; | ||
sl(n); sl(q); | ||
ll arr[n]; | ||
R(i,n){ | ||
sl(arr[i]); | ||
} | ||
|
||
ll *xorArr = new ll[n]; | ||
int abc[1000001]; | ||
fill_n(abc,1000001,0); | ||
|
||
// Initialize first element of prefix array | ||
xorArr[0] = arr[0]; | ||
abc[arr[0]]++; | ||
// Computing the prefix array. | ||
for (ll i = 1; i < n; i++){ | ||
xorArr[i] = xorArr[i-1] ^ arr[i]; | ||
abc[xorArr[i]]++; | ||
} | ||
|
||
ll x,y,z; | ||
R(i,q){ | ||
sl(x);sl(y);sl(z); | ||
if(x==1){ | ||
int temp=arr[y-1]; | ||
arr[y-1]=z; | ||
if(y>1){ | ||
for (ll xx = y-1; xx < n; xx++){ | ||
abc[xorArr[xx]]--; | ||
xorArr[xx] = xorArr[xx-1] ^ arr[xx]; | ||
abc[xorArr[xx]]++; | ||
} | ||
} else { | ||
abc[xorArr[0]]--; | ||
abc[z]++; | ||
xorArr[0]=z; | ||
for (ll yy = 1; yy < n; yy++){ | ||
abc[xorArr[yy]]--; | ||
xorArr[yy] = xorArr[yy-1] ^ arr[yy]; | ||
abc[xorArr[yy]]++; | ||
} | ||
} | ||
} else { | ||
|
||
printf("%lld\n",ans ); | ||
|
||
} | ||
} | ||
|
||
|
||
|
||
return 0; | ||
} |
Oops, something went wrong.