Editing
2015 Open Bronze Problem 2 Bessie Gets Even
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Code == === C++ === <pre> #include <iostream> #include <cstdio> using namespace std; int num[256][2]; bool is_even(int x) { return x % 2 == 0; } int main() { freopen("geteven.in", "r", stdin); freopen("geteven.out", "w", stdout); int N; cin >> N; for (int i = 0; i < N; i++) { char letter; int val; cin >> letter >> val; num[letter][val % 2]++; } int result = 0; for(int B = 0; B < 2; B++) for(int E = 0; E < 2; E++) for(int S = 0; S < 2; S++) for(int I = 0; I < 2; I++) for(int G = 0; G < 2; G++) for(int O = 0; O < 2; O++) for(int M = 0; M < 2; M++) { int expression = (B + E + S + S + I + E) * (G + O + E + S) * (M + O + O); if (is_even(expression)) { result += num['B'][B] * num['E'][E] * num['S'][S] * num['I'][I] * num['G'][G] * num['O'][O] * num['M'][M]; } } cout << result << endl; return 0; } </pre> === Java === <pre> import java.util.*; import java.io.*; public class BessieGetsEven { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("geteven.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("geteven.out"))); int N = Integer.parseInt(in.readLine()); int[][] num = new int[256][2]; for (int i = 0; i < N; i++) { StringTokenizer st = new StringTokenizer(in.readLine()); char letter = st.nextToken().charAt(0); int val = Integer.parseInt(st.nextToken()); num[letter][val % 2]++; } int result = 0; for(int B = 0; B < 2; B++) for(int E = 0; E < 2; E++) for(int S = 0; S < 2; S++) for(int I = 0; I < 2; I++) for(int G = 0; G < 2; G++) for(int O = 0; O < 2; O++) for(int M = 0; M < 2; M++) { int expression = (B + E + S + S + I + E) * (G + O + E + S) * (M + O + O); if (expression % 2 == 0) { result += num['B'][B] * num['E'][E] * num['S'][S] * num['I'][I] * num['G'][G] * num['O'][O] * num['M'][M]; } } out.println(result); out.close(); } } </pre> === Python === <pre> def is_even(x): return x % 2 == 0 num = {c: [0, 0] for c in 'BESIGOM'} with open('geteven.in', 'r') as fin, open('geteven.out', 'w') as fout: N = int(fin.readline().strip()) for _ in range(N): letter, val = fin.readline().strip().split() val = int(val) if is_even(val): num[letter][0] += 1 else: num[letter][1] += 1 result = 0 for B in range(2): for E in range(2): for S in range(2): for I in range(2): for G in range(2): for O in range(2): for M in range(2): if is_even((B + E + S + S + I + E) * (G + O + E + S) * (M + O + O)): result += num['B'][B] * num['E'][E] * num['S'][S] * num['I'][I] * num['G'][G] * num['O'][O] * num['M'][M] fout.write(f"{result}\n") </pre> [[Category:Yearly_2014_2015]] [[Category:Bronze]] [[Category:Arrays]] [[Category:Counting]] [[Category:Brute Force]]
Summary:
Please note that all contributions to Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
My wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information