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 c20480c

Browse files
IvanIvan
Ivan
authored and
Ivan
committed
COCI
1 parent fd311c8 commit c20480c

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

‎DMOJ/coci08c2p5.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding : utf-8 -*-
2+
3+
entrada = input()
4+
5+
somatorio = 1
6+
nos = 1
7+
8+
for caractere in entrada:
9+
if caractere == "P":
10+
continue
11+
elif caractere == "L":
12+
somatorio = somatorio * 2
13+
elif caractere == "R":
14+
somatorio = somatorio*2 + nos
15+
else:
16+
somatorio = somatorio*5 + nos
17+
nos *= 3
18+
19+
print(somatorio)

‎DMOJ/coci08c5p4.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
typedef long long ll;
5+
6+
const int MAXN = (1 << 20) + 10;
7+
const int MAXL = 22;
8+
9+
char entrada[MAXL];
10+
int visto[MAXN],mascaras[MAXL],tudo_ligado,H,N;
11+
ll soma_acumulada[MAXN],total_soma;
12+
13+
int main(){
14+
15+
cin >> N >> H;
16+
tudo_ligado = (1 << N) - 1;
17+
for(int i = 0;i<N;i++){
18+
cin >> entrada;
19+
for(int j = 0;j<N;j++){
20+
if(entrada[j] == '1') mascaras[i] |= (1 << j);
21+
}
22+
}
23+
24+
H--;
25+
total_soma += __builtin_popcount(mascaras[0]);
26+
int bitmask_hoje = mascaras[0];
27+
28+
for(int dia = 1;dia<= H;dia++){
29+
30+
if(visto[bitmask_hoje] != 0){
31+
int comeco = visto[bitmask_hoje];
32+
int periodo = dia - comeco;
33+
H = H - dia + 1;
34+
total_soma += 1LL*(soma_acumulada[dia - 1] - soma_acumulada[comeco - 1])*(H/periodo);
35+
int resto = H % periodo;
36+
if(resto != 0) total_soma += soma_acumulada[comeco + resto - 1] - soma_acumulada[comeco - 1];
37+
break;
38+
}
39+
40+
int nova_bitmask = 0,somatorio_hoje = 0;
41+
visto[bitmask_hoje] = dia;
42+
for(int i = 0;i<N;i++){
43+
int recebeu = __builtin_popcount(bitmask_hoje & mascaras[i]) + __builtin_popcount((bitmask_hoje ^ tudo_ligado) & mascaras[i])*2;
44+
somatorio_hoje += recebeu;
45+
if(recebeu % 2 == 1) nova_bitmask |= (1 << i);
46+
}
47+
48+
total_soma += somatorio_hoje;
49+
soma_acumulada[dia] = soma_acumulada[dia - 1] + 1LL*somatorio_hoje;
50+
bitmask_hoje = nova_bitmask;
51+
52+
}
53+
54+
cout << total_soma << endl;
55+
56+
return 0;
57+
}

‎SPOJ/C1LJUTNJ.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
typedef long long ll;
5+
typedef pair<int,int> ii;
6+
7+
int N,M;
8+
vector<ii> guloso;
9+
ll resposta;
10+
11+
int main(){
12+
13+
scanf("%d %d",&M,&N);
14+
guloso.push_back(ii(0,0));
15+
for(int i = 1;i<=N;i++){
16+
int x;
17+
scanf("%d",&x);
18+
guloso.push_back(ii(x,1));
19+
}
20+
sort(guloso.begin(),guloso.end());
21+
22+
while(M > 0){
23+
int diferenca = guloso.back().first - guloso[guloso.size() - 2].first,tamanho = guloso.back().second;
24+
//printf("Diferenca %d Tamanho %d\n",diferenca,tamanho);
25+
ll precisa = diferenca*guloso.back().second;
26+
if(precisa <= M){
27+
M -= precisa;
28+
guloso.pop_back();
29+
guloso.back().second += tamanho;
30+
}
31+
else{
32+
ll paratodos = M/tamanho;
33+
ll resta = M % tamanho;
34+
guloso.back().first -= paratodos;
35+
guloso.back().second -= resta;
36+
guloso.push_back(ii(guloso.back().first - 1,resta));
37+
M = 0;
38+
}
39+
}
40+
41+
for(ii pares : guloso){
42+
resposta += 1LL*pares.first*pares.first*pares.second;
43+
}
44+
45+
printf("%lld\n",resposta);
46+
47+
return 0;
48+
}

0 commit comments

Comments
(0)

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