Skip to content

Commit 072bf77

Browse files
committed
RPC Ronda 5 - 4 Soluciones
1 parent d167656 commit 072bf77

File tree

4 files changed

+312
-0
lines changed

4 files changed

+312
-0
lines changed
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
import java.io.BufferedReader;
3+
import java.io.InputStreamReader;
4+
import java.util.Arrays;
5+
6+
public class elephants {
7+
8+
public static void main(String[] args) {
9+
try {
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
int N = Integer.parseInt(br.readLine());
12+
13+
String linea, nums;
14+
String[] ar;
15+
int M, W, aux = 0, cont = 0;
16+
int[] ar2;
17+
for (int i = 0; i < N; i++) {
18+
nums = br.readLine();
19+
M = Integer.parseInt(nums.split(" ")[0]);
20+
W = Integer.parseInt(nums.split(" ")[1]);
21+
linea = br.readLine();
22+
ar = linea.split(" ");
23+
ar2 = new int[ar.length];
24+
for (int j = 0; j < ar.length; j++) {
25+
ar2[j] = Integer.parseInt(ar[j]);
26+
}
27+
Arrays.sort(ar2);
28+
for (int j = 0; j < ar2.length; j++) {
29+
aux += ar2[j];
30+
if (aux <= W) {
31+
cont++;
32+
}
33+
}
34+
System.out.println(cont);
35+
cont=0;
36+
aux=0;
37+
}
38+
39+
} catch (Exception ex) {
40+
41+
}
42+
}
43+
44+
}

Competencias 2016/RPC/5/juanma.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <bits/stdc++.h>
2+
/**************************************************************
3+
*Problem Name --> *
4+
*Author --> Sebastreak *
5+
*Date --> 05/16/2016 *
6+
*Platform --> *
7+
*Compiler --> GNU GCC 4.9.0 *
8+
***************************************************************/
9+
#define mod 1000000007
10+
#define pow2(i) (1<<i)
11+
#define bit(i) (1<<i)
12+
#define isOdd(i) (i&1)
13+
#define isEven(i) (!(i&1))
14+
#define sz(i) i.size()
15+
#define REP(i, b, n) for (int i = b; i < n; i++)
16+
#define REPI(i, b, n) for (int i = b; i <= n; i++)
17+
#define rep(i, n) REP(i, 0, n)
18+
#define repi(i, n) REPI(i, 1, n)
19+
#define PB push_back
20+
#define MP make_pair
21+
#define fill(a, val) memset(a,val, sizeof(a))
22+
23+
using namespace std;
24+
long long sum, n;
25+
long long parts(long long n)
26+
{
27+
rep(j, n)
28+
{
29+
rep(i, n)
30+
{
31+
if(i>j)
32+
{
33+
if(j == 0)
34+
sum++;
35+
else
36+
{
37+
if(abs(j - i) > 1)
38+
{
39+
sum += (long long)((abs(j-i) - 1LL)*(long long)j + 1LL);
40+
}else
41+
sum++;
42+
}
43+
}
44+
}
45+
}
46+
return sum;
47+
}
48+
int main ()
49+
{
50+
//freopen("ex.in","r",stdin);
51+
//freopen("ex.out","w",stdout);
52+
int tc;
53+
scanf("%d", &tc);
54+
while(tc--)
55+
{
56+
sum = 1LL;
57+
scanf("%lld", &n);
58+
printf("%lld\n", parts(n));
59+
}
60+
return 0;
61+
}

Competencias 2016/RPC/5/royale.cpp

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include <bits/stdc++.h>
2+
/**************************************************************
3+
*Problem Name --> *
4+
*Author --> Sebastreak *
5+
*Date --> 05/16/2016 *
6+
*Platform --> *
7+
*Compiler --> GNU GCC 4.9.0 *
8+
***************************************************************/
9+
#define mod 1000000007
10+
#define pow2(i) (1<<i)
11+
#define bit(i) (1<<i)
12+
#define isOdd(i) (i&1)
13+
#define isEven(i) (!(i&1))
14+
#define sz(i) i.size()
15+
#define REP(i, b, n) for (int i = b; i < n; i++)
16+
#define REPI(i, b, n) for (int i = b; i <= n; i++)
17+
#define rep(i, n) REP(i, 0, n)
18+
#define repi(i, n) REPI(i, 1, n)
19+
#define PB push_back
20+
#define MP make_pair
21+
#define fill(a, val) memset(a,val, sizeof(a))
22+
23+
using namespace std;
24+
int conver(int a)
25+
{
26+
if(a == 2)
27+
return 5;
28+
else if(a == 5)
29+
return 2;
30+
else if(a == 6)
31+
return 9;
32+
else if(a == 9)
33+
return 6;
34+
return a;
35+
}
36+
int main ()
37+
{
38+
//freopen("ex.in","r",stdin);
39+
//freopen("ex.out","w",stdout);
40+
ios_base::sync_with_stdio(false);
41+
string input;
42+
while(cin>>input)
43+
{
44+
if(cin.eof())
45+
break;
46+
int ar[26];
47+
rep(i, 26)
48+
ar[i] = -1;
49+
int count = 0;
50+
for(int i = 0; i < input.size(); i++)
51+
{
52+
if(ar[input[i] - 'a'] == -1)
53+
{
54+
ar[input[i] - 'a'] = ++count;
55+
if(ar[input[i] - 'a'] < 10)
56+
{
57+
cout<<conver(ar[input[i] - 'a']);
58+
}else
59+
{
60+
cout<<conver(ar[input[i] - 'a']/10)*10+conver(ar[input[i] - 'a']%10);
61+
}
62+
}else
63+
{
64+
if(ar[input[i] - 'a'] < 10)
65+
{
66+
cout<<conver(ar[input[i] - 'a']);
67+
}else
68+
{
69+
cout<<conver(ar[input[i] - 'a']/10)*10+conver(ar[input[i] - 'a']%10);
70+
}
71+
}
72+
}
73+
cout<<'\n';
74+
}
75+
return 0;
76+
}
77+

Competencias 2016/RPC/5/sudoku.java

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
2+
import java.io.BufferedReader;
3+
import java.io.InputStreamReader;
4+
import java.util.Scanner;
5+
6+
public class sudoku {
7+
8+
static int array[];
9+
10+
public static void main(String[] args) {
11+
try {
12+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
13+
Scanner tec = new Scanner(System.in);
14+
int N = 0, T, raiz;
15+
String a = "";
16+
T = tec.nextInt();
17+
18+
int m[][];
19+
int row = 0, cell = 0, cont = 0;
20+
boolean state = true;
21+
int j, k;
22+
int suma, c = 0, aux = 0, pos = 0;
23+
24+
for (int i = 0; i < T; i++) {
25+
state = true;
26+
a = "";
27+
N = tec.nextInt();
28+
29+
if (N == 1) {
30+
System.out.println("yes");
31+
} else {
32+
aux = 0;
33+
c = 0;
34+
35+
m = new int[N][N];
36+
suma = (N * (N + 1)) / 2;
37+
for (j = 0; j < N; j++) {
38+
for (k = 0; k < N; k++) {
39+
m[j][k] = tec.nextInt();
40+
41+
c += m[j][k];
42+
}
43+
if (c == suma) {
44+
c = 0;
45+
aux++;
46+
}
47+
}
48+
if (aux == N && state) {
49+
50+
if (getCount(m, suma)) {
51+
52+
raiz = (int) Math.sqrt((double) N);
53+
String res = "";
54+
row = cell = cont = 0;
55+
for (j = 0; j < raiz; j++) {
56+
array = new int[N];
57+
pos = 0;
58+
if (state) {
59+
for (k = row; k < row + raiz; k++) {
60+
for (int l = cell; l < cell + raiz; l++) {
61+
int h = m[k][l];
62+
63+
if (isFound(h)) {
64+
k = l = raiz;
65+
state = false;
66+
} else {
67+
array[pos] = h;
68+
res += h;
69+
pos++;
70+
cont++;
71+
if (cont == (N * N)) {
72+
state = false;
73+
}
74+
}
75+
}
76+
}
77+
if ((j + 1) % raiz == 0 && j != 0 && state) {
78+
row += raiz;
79+
cell = 0;
80+
j = -1;
81+
} else {
82+
cell = (j + 1) * raiz;
83+
}
84+
res = "";
85+
} else {
86+
break;
87+
}
88+
}
89+
System.out.println(cont == (N * N) ? "yes" : "no");
90+
} else {
91+
System.out.println("no");
92+
}
93+
} else {
94+
System.out.println("no");
95+
96+
}
97+
}
98+
}
99+
} catch (Exception ex) {
100+
}
101+
}
102+
103+
public static boolean isFound(int num) {
104+
for (int i = 0; i < array.length; i++) {
105+
if (array[i] == num) {
106+
return true;
107+
}
108+
}
109+
return false;
110+
}
111+
112+
public static boolean getCount(int m[][], int suma) {
113+
int tam = m.length, cont = 0, aux = 0;
114+
115+
for (int j = 0; j < tam; j++) {
116+
for (int i = 0; i < tam; i++) {
117+
cont += m[i][j];
118+
}
119+
if (cont == suma) {
120+
aux++;
121+
cont = 0;
122+
} else {
123+
j = tam;
124+
break;
125+
}
126+
}
127+
return aux == tam;
128+
}
129+
130+
}

0 commit comments

Comments
 (0)