Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit 24b02c3

Browse files
authored
Add files via upload
1 parent a7477d7 commit 24b02c3

File tree

3 files changed

+262
-39
lines changed

3 files changed

+262
-39
lines changed

citystate.java

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,42 @@
11
import java.io.*;
22
import java.util.*;
3+
34
public class citystate {
4-
public static double decify(int num) {
5-
return 0.01*num;
6-
}
7-
public static void main(String[] args) throws Exception {
8-
// TODO Auto-generated method stub
9-
BufferedReader f=new BufferedReader(new FileReader("citystate.in"));
5+
public static void main(String[] args) throws IOException{
106
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("citystate.out")));
11-
double c1,c2;
7+
BufferedReader f=new BufferedReader(new FileReader("2.in"));
8+
int answer=0;
129
int N=Integer.parseInt(f.readLine());
13-
String[] state=new String[N];//INIT storage for state
14-
String[] city=new String[N];//INIT storage for city
15-
ArrayList<String> hitstates=new ArrayList<String>();
16-
ArrayList<String> hitcities=new ArrayList<String>();
10+
List<String> k=new ArrayList<String>();
11+
List<String> checkstate=new ArrayList<String>();
1712
StringTokenizer st;
1813
for(int i=0;i<N;i++) {
1914
st=new StringTokenizer(f.readLine());
20-
state[i]=st.nextToken();
21-
city[i]=st.nextToken();
22-
//System.out.println("READ");
15+
checkstate.add(st.nextToken());
16+
k.add(st.nextToken());
2317

2418
}
25-
int a,b,c,d,e;
26-
e=0;
19+
String state,city;
2720
for(int i=0;i<N;i++) {
28-
a=((int) city[i].charAt(0)) -(int) ' ';
29-
b=((int) city[i].charAt(1))-(int) ' ';
30-
c1=(((double)a)+(decify(b)));
31-
for(int j=i+1;j<N;j++) {
32-
if(j==i) {
21+
state=checkstate.get(0);
22+
city=k.get(0);
23+
for(int j=0;j<k.size();j++) {
24+
25+
if(i==j) {
3326
continue;
3427
}
35-
c=((int) state[j].charAt(0))-(int) ' ';
36-
d=((int) state[j].charAt(1))-(int) ' ';
37-
c2=(((double)c)+decify(d));
38-
39-
//System.out.println("Debug "+c1+" , "+c2+" "+state[j].charAt(0)+state[j].charAt(1)+" "+city[i].charAt(0)+city[i].charAt(1));
40-
if(c2==c1) {
41-
42-
//System.out.println("HIT");
43-
//System.out.println(city[i]+" "+state[j]+" "+city[j]+" "+state[i]);
44-
if(city[j].equals(state[i].substring(0, 2))){
45-
e++;
46-
}
28+
if(k.get(j).equals(state.substring(0,2))&&!(checkstate.get(j).equals(state))) {
29+
answer++;
30+
System.out.println(k.get(j)+" is equal to "+state);
4731
}
4832
}
33+
k.remove(0);
34+
checkstate.remove(0);
35+
//System.out.println(city+" "+state);
36+
4937
}
50-
//String a1,a2;
51-
52-
53-
pw.println(e);
38+
pw.println(answer);
5439
pw.close();
5540
f.close();
5641
}
57-
58-
5942
}

cowsignal.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import java.io.*;
2+
import java.util.*;
3+
public class cowsignal {
4+
private static int K;
5+
public static ArrayList<ArrayList<Character>> build(ArrayList<ArrayList<Character>> map,int y,char l){
6+
for(int i=y*K;i<((y+1)*K);i++) {
7+
for(int j=0;j<K;j++) {
8+
map.get(i)
9+
.add(l);
10+
};
11+
}
12+
return map;
13+
}
14+
//private static final char s_OFF = 'B';
15+
//private static final char s_ON = '.';
16+
public static void main(String[] args) throws IOException{
17+
BufferedReader f=new BufferedReader(new FileReader("cowsignal.in"));
18+
StringTokenizer st=new StringTokenizer(f.readLine());
19+
int M=Integer.parseInt(st.nextToken());
20+
int N=Integer.parseInt(st.nextToken());
21+
K=Integer.parseInt(st.nextToken());
22+
String temp;
23+
ArrayList<ArrayList<Character>> omap=new ArrayList<ArrayList<Character>>();
24+
for(int i=0;i<(M*K);i++){
25+
26+
omap.add(new ArrayList<Character>());
27+
}
28+
System.out.println("M*K "+M*K);
29+
//Character[][] map=new Character[M][N];
30+
for(int i=0;i<M;i++) {
31+
temp=f.readLine();
32+
for(int j=0;j<N;j++) {
33+
//map[i][j]=temp.charAt(j);
34+
omap=build(omap,i,temp.charAt(j));
35+
}
36+
}
37+
f.close();
38+
PrintWriter out=new PrintWriter(new FileWriter("cowsignal.out"));
39+
for(int i=0;i<(M*K);i++) {
40+
for(int j=0;j<(N*K);j++) {
41+
out.print(omap.get(i).get(j));
42+
}
43+
out.println();
44+
}
45+
out.flush();
46+
out.close();
47+
48+
49+
50+
}
51+
52+
}

cowtiper.java

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import java.io.*;
2+
//import java.util.*;
3+
import modules.PrettyPrinter;
4+
public class cowtiper {
5+
private static int[][] field;
6+
private static int N;
7+
private static boolean patch;
8+
public static int c(char bit) {
9+
switch(bit) {
10+
case '1':
11+
patch=false;
12+
return 1;
13+
case '0':
14+
return 0;
15+
default:
16+
return -1;
17+
}
18+
}
19+
public static int sum(int[][] a) {
20+
/*
21+
* Finds total amount of cows not tipped over
22+
*/
23+
int out=0;
24+
for(int i=0;i<N;i++) {
25+
for(int j=0;j<N;j++) {
26+
if(a[i][j]==0) {
27+
out++;
28+
}
29+
}
30+
}
31+
return out;
32+
}
33+
public static int[][] invert(int[][] a){
34+
for(int i=0;i<N;i++) {
35+
for(int j=0;j<N;j++) {
36+
37+
if(a[i][j]==1) {
38+
a[i][j]=0;
39+
}else if(a[i][j]==0) {
40+
a[i][j]=1;
41+
}
42+
43+
}
44+
}
45+
return a;
46+
}
47+
public static int[][] invert(int[][] a,int x,int y){
48+
for(int i=0;i<x;i++) {
49+
for(int j=0;j<y;j++) {
50+
System.out.println("Invert X:"+i+" Y:"+j+"");
51+
52+
if(a[i][j]==1) {
53+
a[i][j]=0;
54+
}else if(a[i][j]==0) {
55+
a[i][j]=1;
56+
}
57+
58+
}
59+
}
60+
return a;
61+
}
62+
public static int[][] best(int[][] a){
63+
int temp=sum(a);
64+
if(temp<((N*N)-temp)) {
65+
a=invert(a);
66+
}
67+
return a;
68+
}
69+
public static int[][] best_NS(int[][] a){
70+
int temp=sum(a);
71+
if(temp<((N*N)-temp)) {
72+
a=invert(a);
73+
}
74+
return a;
75+
}
76+
public static int[][] best(int[][] a,int x,int y){
77+
int temp=sum(a);
78+
if(temp<((N*N)-temp)) {
79+
a=invert(a,x,y);
80+
}
81+
return a;
82+
}
83+
public static int[][] best_NS(int[][] a,int x,int y){
84+
int temp=sum(a);
85+
if(temp<((N*N)-temp)) {
86+
a=invert(a,x,y);
87+
}
88+
return a;
89+
}
90+
public static void showfield() {
91+
String[][] ppa=new String[N][N];
92+
//field=best(field);
93+
PrettyPrinter pp=new PrettyPrinter(System.out);
94+
for(int i = 0; i < N; i++)
95+
{
96+
for(int j = 0; j < N; j++)
97+
ppa[i][j] = Integer.toString(field[i][j]);
98+
}
99+
pp.print(ppa);
100+
}
101+
102+
public static int hx(int[][] a) {
103+
int l=0;
104+
for(int i=0;i<N;i++) {
105+
for(int j=0;j<N;j++) {
106+
if(a[i][j]==1) {
107+
if(i>l) {
108+
l=i;
109+
}
110+
}
111+
}
112+
}
113+
return l;
114+
}
115+
public static int hy(int[][] a) {
116+
int l=-1;
117+
for(int i=0;i<N;i++) {
118+
for(int j=0;j<N;j++) {
119+
if(a[i][j]==1) {
120+
if(j>l) {
121+
l=j;
122+
}
123+
}
124+
}
125+
}
126+
return l;
127+
}
128+
public static void main(String[] args) throws Exception{
129+
// TODO Auto-generated method stub
130+
BufferedReader f=new BufferedReader(new FileReader("5(1).in"));
131+
N = Integer.parseInt(f.readLine());
132+
field = new int[N][N];
133+
134+
String temp;
135+
patch = true;
136+
for(int i=0;i<N;i++) {
137+
temp=f.readLine();
138+
for(int j=0;j<N;j++) {
139+
field[i][j]=c(temp.charAt(j));
140+
//Integer.parseInt(Character.toString(temp.charAt(j)));
141+
}
142+
}
143+
f.close();
144+
//Begin debug zone
145+
showfield();
146+
String[][] ppa=new String[N][N];
147+
148+
field=best(field); // DO NOT REMOVE
149+
150+
PrettyPrinter pp=new PrettyPrinter(System.out);
151+
for(int i = 0; i < N; i++)
152+
{
153+
for(int j = 0; j < N; j++)
154+
ppa[i][j] = Integer.toString(field[i][j]);
155+
}
156+
pp.print(ppa);
157+
158+
//End debug zone
159+
int test=0;
160+
//if(sum(field)==(N*N)) {
161+
test=0;
162+
//}else {
163+
test=1;
164+
165+
while(sum(field)!=(N*N)) {
166+
//if()
167+
showfield();
168+
System.out.println(hx(field));
169+
System.out.println(hy(field));
170+
field=invert(field,hx(field)+1,hy(field)+1);
171+
showfield();//Debug
172+
//Thread.sleep(500);
173+
test++;
174+
if(test>10000) {
175+
throw new Exception("Auto terminate");
176+
}
177+
}
178+
//}
179+
180+
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("cowtip.out")));
181+
if(patch) {test=0;}
182+
pw.println(test);
183+
pw.flush();
184+
pw.close();
185+
186+
}
187+
188+
}

0 commit comments

Comments
 (0)