Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bceb126

Browse files
Even more DMOJ !
1 parent 79ce82c commit bceb126

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+3718
-0
lines changed

‎DMOJ/bf3.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <cstdio>
2+
int primality(int x){
3+
if(x <= 1) return 0;
4+
if(x == 2 || x == 3) return 1;
5+
if(x % 2 == 0 || x % 3 == 0) return 0;
6+
for(int i = 5;i*i <= x;i += 6){
7+
if(x % i == 0) return 0;
8+
if(x % (i+2) == 0) return 0;
9+
}
10+
return 1;
11+
}
12+
int main(){
13+
int n;
14+
scanf("%d",&n);
15+
int limit = 0;
16+
for(int i=0;i<=30;i++) limit += (1<<i);
17+
for(int i = n;i<=limit;i++){
18+
if(primality(i)){
19+
printf("%d\n",i);
20+
return 0;
21+
}
22+
}
23+
return 0;
24+
}

‎DMOJ/bf4hard.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <cstdio>
2+
#include <cstring>
3+
#include <set>
4+
using namespace std;
5+
int freq[2010];
6+
int esperado[2010];
7+
char W[1000010],S[1000010];
8+
int m,n;
9+
int correto;
10+
void add(char c){
11+
freq[c]++;
12+
if(freq[c] == esperado[c]){
13+
correto++;
14+
}
15+
else if(freq[c] == esperado[c] + 1){
16+
correto--;
17+
}
18+
}
19+
void remove(char c){
20+
freq[c]--;
21+
if(freq[c] == esperado[c]){
22+
correto++;
23+
}
24+
else if(freq[c] == esperado[c] - 1){
25+
correto--;
26+
}
27+
}
28+
int checa(int comeco){
29+
for(int i = comeco,j = 0;j < m;i++,j++){
30+
if(W[j] != S[i]){
31+
return 0;
32+
}
33+
}
34+
return 1;
35+
}
36+
int main(){
37+
set<char> conjunto;
38+
scanf("%s",S);
39+
scanf("%s",W);
40+
n = strlen(S);
41+
m = strlen(W);
42+
for(int i=0;i<m;i++){
43+
conjunto.insert(W[i]);
44+
esperado[W[i]]++;
45+
}
46+
correto = 26 - (int)conjunto.size();
47+
for(int i=0;i<m;i++){
48+
add(S[i]);
49+
}
50+
if(correto == 26 && checa(0)){
51+
printf("0\n");
52+
return 0;
53+
}
54+
for(int i = m;i<n;i++){
55+
remove(S[i-m]);
56+
add(S[i]);
57+
if(correto == 26 && checa(i-m+1)){
58+
printf("%d\n",i-m+1);
59+
return 0;
60+
}
61+
}
62+
printf("-1\n");
63+
return 0;
64+
}

‎DMOJ/bts16p3.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <cstdio>
2+
#include <cstring>
3+
#define MOD 1000000007
4+
#define MAXN 100010
5+
int dp[MAXN],resp,n,vetor[MAXN];
6+
char entrada[MAXN];
7+
inline int add(int x,int y){
8+
return (x+y)%MOD;
9+
}
10+
int solve(int pos){
11+
if(dp[pos] != -1) return dp[pos];
12+
if(pos == n || vetor[pos+1] != vetor[pos]) return dp[pos] = 1;
13+
return dp[pos] = add(1,solve(pos+1));
14+
}
15+
int main(){
16+
scanf("%d",&n);
17+
for(int i=1;i<=n;i++){
18+
scanf("%s",entrada);
19+
if('a' <= entrada[0] && entrada[0] <= 'z'){
20+
vetor[i] = entrada[0] - 'A';
21+
}
22+
else{
23+
vetor[i] = entrada[0] - 'A';
24+
}
25+
}
26+
//for(int i=1;i<=n;i++) printf("%d ",vetor[i]);
27+
//printf("\n");
28+
memset(dp,-1,sizeof(dp));
29+
for(int i=1;i<=n;i++){
30+
resp = add(resp,solve(i));
31+
}
32+
printf("%d\n",resp);
33+
return 0;
34+
}

‎DMOJ/ccc00s5.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <cstdio>
2+
#include <vector>
3+
#include <queue>
4+
using namespace std;
5+
int processado[110];
6+
double X[110],Y[110],melhor[110];
7+
int main(){
8+
int n;
9+
scanf("%d",&n);
10+
for(int i=1;i<=n;i++){
11+
scanf("%lf %lf",&X[i],&Y[i]);
12+
}
13+
for(double cordx = 0.00;cordx <= 1000.0;cordx+= 0.01){
14+
double best = 1e9;
15+
vector<int> escolhidas;
16+
for(int i=1;i<=n;i++){
17+
double dist = Y[i]*Y[i] + (X[i] - cordx)*(X[i] - cordx);
18+
if(dist < best){
19+
escolhidas.clear();
20+
best = dist;
21+
escolhidas.push_back(i);
22+
}
23+
else if(dist == best){
24+
escolhidas.push_back(i);
25+
}
26+
}
27+
for(int i : escolhidas) processado[i] = 1;
28+
}
29+
for(int i=1;i<=n;i++){
30+
if(processado[i]) printf("The sheep at (%.2lf, %.2lf) might be eaten.\n",X[i],Y[i]);
31+
}
32+
return 0;
33+
}

‎DMOJ/ccc01j2.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <cstdio>
2+
int main(){
3+
int x,m;
4+
scanf("%d %d",&x,&m);
5+
for(int i=1;i<m;i++){
6+
if((x*i) % m == 1){
7+
printf("%d\n",i);
8+
return 0;
9+
}
10+
}
11+
printf("No such integer exists.\n");
12+
return 0;
13+
}

‎DMOJ/ccc01s4.cpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#include <cstdio>
2+
#include <cmath>
3+
#include <vector>
4+
#include <algorithm>
5+
using namespace std;
6+
const double EPS = 1e-5;
7+
double X[2000],Y[2000],squared[2000],x_c,y_c,r;
8+
struct point{
9+
double x,y;
10+
};
11+
int ccw(point A,point B, point C){
12+
double val = A.x*(B.y - C.y) - A.y*(B.x - C.x) + B.x*C.y - B.y*C.x;
13+
if(val >= EPS) return 1;
14+
if(fabs(val) < EPS) return 0;
15+
return -1;
16+
}
17+
bool comp(point A, point B){
18+
if(fabs(A.x - B.x) < EPS){
19+
return A.y + EPS <= B.y;
20+
}
21+
return A.x + EPS <= B.x;
22+
}
23+
vector<point> CH(vector<point> P){
24+
int n = P.size(), k = 0;
25+
sort(P.begin(),P.end(),comp);
26+
vector<point> H(2*n);
27+
for(int i=0;i<n;i++){
28+
while(k >= 2 && ccw(H[k-2],H[k-1],P[i]) <= 0) k--;
29+
H[k++] = P[i];
30+
}
31+
for(int i = n-2, t = k+1;i>=0;i--){
32+
while(k >= t && ccw(H[k-2],H[k-1],P[i]) <= 0) k--;
33+
H[k++] = P[i];
34+
}
35+
H.resize(k-1);
36+
return H;
37+
}
38+
void addCircle(int A,int B,int C, int n){
39+
double cof1 = X[A]*(Y[B] - Y[C]) - Y[A]*(X[B] - X[C]) + X[B]*Y[C] - Y[B]*X[C];
40+
double cof2 = squared[A]*(Y[B] - Y[C]) - Y[A]*(squared[B] - squared[C]) + squared[B]*Y[C] - Y[B]*squared[C];
41+
double cof3 = squared[A]*(X[B] - X[C]) - X[A]*(squared[B] - squared[C]) + squared[B]*X[C] - X[B]*squared[C];
42+
double cof4 = squared[A]*(X[B]*Y[C] - Y[B]*X[C]) - X[A]*(squared[B]*Y[C] - Y[B]*squared[C]) + Y[A]*(squared[B]*X[C] - X[B]*squared[C]);
43+
//printf("Cofs do addCircle(%d,%d,%d,%d)\n",A,B,C,n);
44+
cof2 *= -1;
45+
cof4 *= -1;
46+
for(int i=1;i<=n;i++){
47+
double val = cof1*squared[i] + cof2*X[i] + cof3*Y[i] + cof4;
48+
if(val >= EPS){
49+
return;
50+
}
51+
}
52+
double xdavez = -cof2/(2.0*cof1);
53+
double ydavez = -cof3/(2.0*cof1);
54+
double raiodavez = hypot(X[A] - xdavez, Y[A] - ydavez);
55+
if(raiodavez + EPS <= r){
56+
r =raiodavez;
57+
x_c = xdavez;
58+
y_c = ydavez;
59+
}
60+
}
61+
void addDiameter(int A,int B,int n){
62+
double xdavez = (X[A] + X[B])*0.5;
63+
double ydavez = (Y[A]+Y[B]) *0.5;
64+
double raiodavez = hypot(X[A] - X[B],Y[A] - Y[B]) * 0.5;
65+
for(int i=1;i<=n;i++){
66+
double val = hypot(X[i] - xdavez,Y[i] - ydavez);
67+
if(val >= raiodavez + EPS) return;
68+
}
69+
if(raiodavez + EPS <= r){
70+
r =raiodavez;
71+
x_c = xdavez;
72+
y_c = ydavez;
73+
}
74+
}
75+
int main(){
76+
int n,instancia = 1;
77+
while(scanf("%d",&n) != EOF){
78+
x_c = 1e9;
79+
y_c = 1e9;
80+
r = 1e9;
81+
vector<point> entrada;
82+
for(int i=1;i<=n;i++){
83+
point temp;
84+
scanf("%lf %lf",&temp.x,&temp.y);
85+
entrada.push_back(temp);
86+
}
87+
if(n == 1){
88+
printf("%.2lf\n",0.0);
89+
continue;
90+
}
91+
vector<point> H = CH(entrada);
92+
n = H.size();
93+
for(int i=0;i<n;i++){
94+
X[i+1] = H[i].x;
95+
Y[i+1] = H[i].y;
96+
squared[i+1] = H[i].x*H[i].x + H[i].y*H[i].y;
97+
}
98+
if(n == 2){
99+
x_c = (X[1] + X[2]) * 0.5;
100+
y_c = (Y[1] + Y[2]) * 0.5;
101+
r = hypot(X[1] - X[2],Y[1] - Y[2]) * 0.5;
102+
printf("%.2lf\n",2.0*r);
103+
continue;
104+
}
105+
for(int i=1;i<=n-1;i++){
106+
for(int j=i+1;j<=n;j++){
107+
addDiameter(i,j,n);
108+
}
109+
}
110+
for(int i=1;i<=n-2;i++){
111+
for(int j=i+1;j<=n-1;j++){
112+
for(int k = j+1;k<=n;k++){
113+
addCircle(i,j,k,n);
114+
}
115+
}
116+
}
117+
printf("%.2lf\n",2.0*r);
118+
}
119+
return 0;
120+
}

‎DMOJ/ccc02s4.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <cstring>
4+
#include <algorithm>
5+
using namespace std;
6+
int dp[110];
7+
int nxt[110];
8+
string nomes[110];
9+
int v[110],n,m;
10+
int custo(int ini,int fim){
11+
int r = 0;
12+
for(int i=ini;i<=fim;i++) r = max(r,v[i]);
13+
return r;
14+
}
15+
int solve(int pos){
16+
if(pos == n + 1){
17+
return dp[pos] = 0;
18+
}
19+
if(dp[pos] != -1) return dp[pos];
20+
int best = 1e9;
21+
nxt[pos] = -1;
22+
for(int quebra = pos;quebra <= pos + m - 1;quebra++){
23+
int cand = custo(pos,quebra) + solve(quebra + 1);
24+
if(cand < best){
25+
best = cand;
26+
nxt[pos] = quebra;
27+
}
28+
}
29+
return dp[pos] = best;
30+
}
31+
int main(){
32+
cin >> m >> n;
33+
memset(dp,-1,sizeof(dp));
34+
for(int i=1;i<=n;i++){
35+
cin >> nomes[i];
36+
cin >> v[i];
37+
}
38+
cout << "Total Time: " << solve(1) << endl;
39+
int atual = 1;
40+
while(atual <= n){
41+
for(int i = atual;i<=nxt[atual];i++){
42+
cout << nomes[i] << " ";
43+
}
44+
cout << endl;
45+
atual = nxt[atual] + 1;
46+
}
47+
return 0;
48+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /