Hải Nguyễn

@hainguyen1498

Viet Nam, Ha Noi

Institution: Birla Institute of Technology, Mesra

import java.util.*; import java.lang.*; class Main { private static boolean haveEmpty(char[][] a) { for (int i = 0; i < a.length; i++) for (int j = 0; j < a[0].length; j++) if (a[i][j] == '.') return true; return false; } private static void addNewStudent(char[][]a) { int temp = 0; int max = 0; int x = 0, y = 0; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[0].length; j++) { if(a[i][j] == '.') { for (int k = -1; k < 2; k++) { for (int l = -1; l < 2; l++) { if( (i+k < 0) || (i+k > a.length-1) || (j+l < 0) || (j+l > a[0].length-1)) continue; if ((k!=0 || l!=0) && (a[i+k][j+l] == 'o')) temp++; } } if(max < temp) { max = temp; x = i; y = j; } temp = 0; } } } a[x][y] = 'o'; } private static int handshake(char[][] a) { int res = 0; for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[0].length; j++) { if (a[i][j] == 'o') { if (j<a[0].length-1 && a[i][j+1] == 'o') res++; if (i < a.length-1) { for (int k = -1; k < 2; k++) { if ((j+k < 0) || (j+k > a[0].length-1)) continue; if (a[i+1][j+k] == 'o') res++; } } } } } return res; } public static void main(String[] args) { Scanner input = new Scanner(System.in); int r = input.nextInt(); int c = input.nextInt(); char[][] a = new char[r][c]; String st; input.nextLine(); for (int i = 0; i < r; i++) { st = input.nextLine(); a[i] = st.toCharArray(); } if(haveEmpty(a)) addNewStudent(a); System.out.println(handshake(a)); } } //////////////////// rem cua #include <iostream> using namespace std; void res(char a[][1000], int temp[5], int m, int n) { int counts = 0; for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { for(int k = 0; k < 4; k++) { if(a[i*5+1+k][j*5+1] == '*') counts++; else break; } temp[counts]++; counts = 0; } } } int main() { int T; cin >> T; int m, n; char a[1000][1000]; for(int test_case = 1; test_case <= T; test_case++) { cin >> m >> n; for(int i = 0; i < 5*m+1; i++) for(int j = 0; j < 5*n+1; j++) cin >> a[i][j]; int temp[5]; for(int i = 0; i < 5; i++) temp[i] = 0; res(a, temp, m, n); cout << "#" << test_case; for(int i = 0; i < 5; i++) cout << " " << temp[i]; cout << endl; } return 0; } //// mật khẩu IM /// package com.java.demo; import java.io.File; import java.util.Scanner; public class Main { static boolean checkPass(int[][] a, int id, int pass) { int flag = 0; for(int i = 0; i < 5; i++) { if(pass == a[id-1][i]) return false; if(a[id-1][i] == 0) { a[id-1][i] = pass; flag = 1; break; } } if(flag == 0) { for(int i = 0; i < 4; i++) a[id-1][i] = a[id-1][i+1]; a[id-1][4] = pass; } return true; } public static void main(String args[]) throws Exception { Scanner input = new Scanner(new File("input.txt")); // int T = input.nextInt(); // for(int test_case = 1; test_case <= T; test_case++) // { // int n = input.nextInt(); // int m = input.nextInt(); // int[][] a = new int[m][5]; // for(int i = 0; i < m; i++) // for(int j = 0; j < 5; j++) // a[i][j] = 0; // int id; // int pass; // int fail = 0; // for(int i = 0; i < m; i++) { // id = input.nextInt(); // pass = input.nextInt(); // if(!checkPass(a, id, pass)) // fail++; // } // System.out.println("#" + test_case + " " + fail); // } } } ///// xâu thân thiện//// //// #include <iostream> #include <string> using namespace std; int a[130]; int b[130]; void init() { b[63] = 0;//Dau ? for(int i = 97;i<=122;i++)//duyet chu cai thường từ a --> z { a[i] = 0; b[i] = 0; } } bool accept() { for(int i = 97;i<=122;i++) { if(b[i] > a[i]) return false; } return true; } int main() { freopen("input.txt","r",stdin); string T,S; cin >> T; cin >> S; int res = 0;//biến kết quả int lent = T.length; int lens = S.length; for(int i = 0;i<lens;i++) { int x = (int)S[i]; a[x]++; int y = (int)T[i]; b[y]++; if(accept()) res = 1; } for(int i = 1;i<=lent-lens;i++) { int x = (int)T[i-i]; b[x]--; int y = (int)T[i+lens-1]; b[y]++; if(accept()) res++; } cout<<res; system("pause"); return 0; }

Các lần nộp bài đã được ghi nhân
(Xem dạng tệp tin văn bản)

Problems

Danh sách các bài đã làm đạt yêu cầu:

VMRR

Danh sách các bài làm chưa đạt yêu cầu:

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.