# 20220415_Paiza 成果物
作成日:2022年4月15日
作成者:金子
## B009:カンファレンスのタイムテーブル作成
java 経過時間:約 1時間
```java=
import java.util.*;
/*
3 発表者数
jobs 45 発表者 発表時間
gates 60
larry 15
*/
public class Main {
public static void main(String[] args) {
// スキャナ生成
Scanner sc = new Scanner(System.in);
// 発表者数
int menber = sc.nextInt();
// 時間
int hour = 10;
int min = 00;
// タイムテーブルクラスの配列
TimeTable[] tt = new TimeTable[menber];
// 発表者登録
for(int i = 0; i < menber; i++){
// タイムテーブルを作成して情報を渡す
tt[i] = new TimeTable(sc.next().replaceAll(" ",""), sc.nextInt());
}
// 昼休憩チェック
boolean checkNoon = false;
// 発表者開始
for(int i = 0; i < menber; i++){
// 開始時刻をセット
tt[i].setStartTime(hour, min);
// 発表予想時刻を取得して12じを過ぎていれば昼休憩
if(tt[i].checkTime() && !checkNoon){
checkNoon = true;
// 昼休憩時間
hour++;
// 普通の休憩はない
min -= 10;
// 開始時刻をセット
tt[i].setStartTime(hour, min);
}
// 発表開始
tt[i].presentation();
min = tt[i].getEndM() + 10;
hour = tt[i].getEndH();
// タイムテーブル表示
tt[i].lookTimeTable();
}
}
}
class TimeTable{
private int startH;
private int startM;
private int endH;
private int endM;
private int predictH;
private int predictM;
private String name;
private int publicTime;
public TimeTable(String name, int publicTime){
this.name = name;
this.publicTime = publicTime;
}
// 終了時刻獲得
public int getEndM(){
return endM;
}
public int getEndH(){
return endH;
}
// 発表開始
public void presentation(){
int tempM;
tempM = startM + publicTime;
endM = tempM % 60;
endH = startH + tempM / 60;
}
// 発表終了時刻を予想
private void predict(){
int tempM;
tempM = startM + publicTime;
predictM = tempM % 60;
predictH = startH + tempM / 60;
}
// 発表終了時刻が12:01をすぎるかどうか
public boolean checkTime(){
predict();
if(12 < predictH){
return true;
}else if(12 == predictH && predictM == 0){
return false;
}else if(12 <= predictH){
return true;
}
return false;
}
// 開始時刻をセット
public void setStartTime(int startH, int startM){
this.startM = startM % 60;
this.startH = startH + (startM / 60);
}
// タイムテーブル表示
public void lookTimeTable(){
lookStartTime();
System.out.print(" - ");
lookEndTime();
lookName();
}
// 発表開始時刻表示
private void lookStartTime(){
System.out.print(startH + ":" + String.format("%02d", startM));
}
// 発表終了時刻表示
private void lookEndTime(){
System.out.print(endH + ":" + String.format("%02d", endM));
}
// 発表者の名前表示
private void lookName(){
System.out.println(" " + name);
}
}
```
## B072:反転スイッチ
java 解答時間: 34分58秒
```java=
import java.util.*;
/*
4 4 縦 横
3 3 反転の 縦 横
#__ 斑点模様
###
#__
2 スイッチ押下回数
1 1 座標
2 2
*/
public class Main {
public static void main(String[] args) {
// スキャナ
Scanner sc = new Scanner(System.in);
// 縦 横
int height = sc.nextInt();
int width = sc.nextInt();
// 反転模様の縦 横
int heightR = sc.nextInt();
int widthR = sc.nextInt();
// 反転模様格納
String line = "";
char[][] reverse = new char[heightR][widthR];
for(int i = 0; i < heightR; i++){
line = sc.next();
for(int j = 0; j < widthR; j++){
reverse[i][j] = line.charAt(j);
}
}
// スイッチ押下回数
int push = sc.nextInt();
// フィールド生成
char[][] field = new char[height][width];
// '_'で初期化
for(char[] oneLine : field){
Arrays.fill(oneLine, '_');
}
int x = 0, y = 0;
// 反転させていく
for(int i = 0; i < push; i++){
// 座標取得
x = sc.nextInt() - 1;
y = sc.nextInt() - 1;
// 押下
for(int j = y, jR = 0; j < y + heightR; j++, jR++){
for(int k = x, kR = 0; k < x + widthR; k++, kR++){
try{
if(reverse[jR][kR] == '#' && field[j][k] == '#'){
field[j][k] = '_';
}else if(reverse[jR][kR] == '#' && field[j][k] == '_'){
field[j][k] = '#';
}
}catch(Exception e){}
}
}
}
for(char[] oneLine : field){
System.out.println(oneLine);
}
}
}
```
## B084:オススメのお店
java 解答時間: 46分14秒
```java=
import java.util.*;
/*
4 3 2 店数 他のユーザー数 好みが似ているといえる基準
3 0 3 0 自分の店ごとの評価
3 3 3 1 他人の店ごとの評価
1 3 1 3
3 0 3 3
*/
public class Main {
public static void main(String[] args) {
// スキャナ生成
Scanner sc = new Scanner(System.in);
// 店数 他のユーザー数 好みが似ているといえる基準
int shopNum = sc.nextInt();
int userNum = sc.nextInt();
int border = sc.nextInt();
// 自分の評価
int[] myEvaluation = new int[shopNum];
for(int i = 0; i < shopNum; i++){
myEvaluation[i] = sc.nextInt();
}
// 他人配列生成
MoreUser[] user = new MoreUser[userNum];
// 評価配列
int[] evaluation = new int[shopNum];
for(int i = 0; i < userNum; i++){
Arrays.fill(evaluation, 0);
for(int j = 0; j < shopNum; j++){
evaluation[j] = sc.nextInt();
}
user[i] = new MoreUser(evaluation);
}
// 似ている人リスト
List<MoreUser> nierList = new ArrayList<MoreUser>();
// 似ている人をチェック
for(MoreUser mu : user){
// 星3がかぶった数をカウント
int count = 0;
for(int i = 0; i < shopNum; i++){
if(myEvaluation[i] == 3 && mu.getEvaluation(i) == 3){
count++;
}
}
// 一致数が一定数を超えていたら
if(border <= count){
nierList.add(mu);
}
}
// ログリスト
List<Integer> logList = new ArrayList<Integer>();
// 似ている人リストの中から
// 自分が行っていない店 かつ 似てる人が星3をつけた店を探す
for(int i = 0; i < shopNum; i++){
// 行ったことない店
if(myEvaluation[i] == 0){
for(MoreUser nierUser : nierList){
// 似てる人が星3 かつ 一度も出力したことない
if(nierUser.getEvaluation(i) == 3 && !logList.contains(i + 1)){
logList.add(i+1);
}
}
}
}
if(logList.isEmpty()){
System.out.println("no");
}else{
// ログを表示
for(int i = 0; i < logList.size(); i++){
System.out.print(logList.get(i));
if(i != logList.size() - 1){
System.out.print(" ");
}else{
System.out.print("\n");
}
}
}
}
}
// 他の人の評価
class MoreUser{
private int[] evaluation;
public MoreUser(int evan[]){
evaluation = new int[evan.length];
for(int i = 0; i < evan.length; i++){
this.evaluation[i] = evan[i];
}
}
// 店の評価を確認
public int getEvaluation(int number){
return evaluation[number];
}
// 店の評価を全て出力
public void showEvaluation(){
for(int i : evaluation){
System.out.print(i + " ");
}
System.out.print("\n");
}
}
```
## B037:幸運な1年
java 解答時間: 65分58秒
```java=
import java.util.*;
/*
・w_{n+1} = (a_1 * w_n + b_1) mod m_1
・x_{n+1} = (a_2 * x_n + b_2) mod m_2
・y_{n+1} = (a_3 * y_n + b_3) mod m_3
・z_{n+1} = (a_4 * z_n + b_4) mod m_4
*/
/*
3 3 月 日
1 1 1 1 a
0 3 0 23 b
100 100 100 100 m
*/
public class Main {
public static void main(String[] args) {
// スキャナ
Scanner sc = new Scanner(System.in);
// 月
int month = sc.nextInt();
// 日
int date = sc.nextInt();
// 今日の日付カード配列
int[] card = new int[4];
card[0] = month < 10 ? 0 : month / 10;
card[1] = month < 10 ? month : month % 10;
card[2] = date < 10 ? 0 : date / 10;
card[3] = date < 10 ? date : date % 10;
// a配列
int[] a_n = new int[4];
// b配列
int[] b_n = new int[4];
// m配列
int[] m_n = new int[4];
for(int i = 0; i < 4; i++){
a_n[i] = sc.nextInt();
}
for(int i = 0; i < 4; i++){
b_n[i] = sc.nextInt();
}
for(int i = 0; i < 4; i++){
m_n[i] = sc.nextInt();
}
// 結果格納配列
int result[] = new int[4];
Arrays.fill(result, 0);
// 引いた数をカウント
int count = 0;
// カードが作れるかチェック
boolean[] checkMake = new boolean[4];
// 比べるようの今日の日付配列
int[] compCard = new int[4];
// 比べる用の引いたカード
int[] drawCard = new int[4];
while(true){
// カウントアップ
count++;
// リセット
Arrays.fill(compCard, 0);
// 疑似乱数を用いてカードを引く
for(int i = 0; i < 4; i++){
result[i] = (a_n[i] * result[i] + b_n[i]) % m_n[i];
drawCard[i] = result[i] % 10;
compCard[i] = card[i];
}
// カードが作れるかチェック
for(int draw : drawCard){
for(int i = 0; i < 4; i++){
// 一致していれば
if(draw == compCard[i]){
compCard[i] = 10;
break;
}
}
}
boolean check = true;
for(int i : compCard){
if(i != 10){
check = false;
break;
}
}
// カードが作れるならば終了
if(check){
System.out.println(count);
System.exit(0);
}
}
}
}
```
## B028:チャット記録
java 解答時間: 42分39秒
```java=
import java.util.*;
/*
4 1 4 社員数 グループ数 メッセージ数
2 3 2 グループの人数 属する人...
1 0 2 from1to2 送信主 送信先 メッセージ
3 1 1 from3togroup1 送信先が 0:個人 1:グループ
3 0 2 from3to2
4 0 1 from4to1
*/
public class Main {
public static void main(String[] args) {
// スキャナ生成
Scanner sc = new Scanner(System.in);
// 社員数
int menber = sc.nextInt();
// グループ数
int groupNum = sc.nextInt();
// メッセージ数
int msgNum = sc.nextInt();
// 社員クラスの配列を生成
Employee[] employee = new Employee[menber];
for(int i = 0; i < menber; i++){
employee[i] = new Employee();
}
// グループ番号を社員に登録
for(int i = 0; i < groupNum; i++){
int groupMenber = sc.nextInt();
for(int j = 0; j < groupMenber; j++){
int empNum = sc.nextInt();
employee[empNum - 1].setGroup(i + 1);
}
}
// 送信主
int from = 0;
// 個人 or グループ
boolean dest = false;
// 送信先
int to = 0;
// 内容
String msg = "";
// メッセージ送受信開始
for(int i = 0; i < msgNum; i++){
// 送信主入力
from = sc.nextInt() - 1;
// グループならtrue
dest = sc.nextInt() != 0;
// 送信先
to = sc.nextInt();
// 内容
msg = sc.nextLine().replaceAll(" ","");
// グループの場合
if(dest){
for(Employee e : employee){
if(e.getGroupEmpty(to)){
e.setMsg(msg);
}
}
// 個人の場合
}else{
// 送信主と送信先に表示
employee[from].setMsg(msg);
employee[to - 1].setMsg(msg);
}
}
// 全員の画面を表示
for(int i = 0; i < menber; i++){
employee[i].showMsg();
if(i != menber - 1){
System.out.println("--");
}
}
}
}
class Employee{
// 受信メッセージを格納
private List<String> msgList = new ArrayList<String>();
// 属するグループの番号が格納
private List<Integer> groupList = new ArrayList<Integer>();
// グループ番号を受け取りそのグループに属していればtrue
public boolean getGroupEmpty(int num){
for(int n : groupList){
if(n == num){
return true;
}
}
return false;
}
// グループ番号登録
public void setGroup(int num){
groupList.add(num);
}
// メッセージ受信
public void setMsg(String msg){
msgList.add(msg);
}
// 受信メッセージ表示
public void showMsg(){
for(String msg : msgList){
System.out.println(msg);
}
}
}
```
## B043:ねずみ小僧
java 解答時間: 24分50秒
```java=
import java.util.*;
/*
4 5 町の 縦 横
2 2 鼠小僧の初期位置 縦 横
.*.*. 町
*....
.*...
.*..*
*/
public class Main {
public static void main(String[] args) {
// スキャナ
Scanner sc = new Scanner(System.in);
// 縦 横
int height = sc.nextInt();
int width = sc.nextInt();
// 鼠小僧の初期位置
int y = sc.nextInt() - 1;
int x = sc.nextInt() - 1;
// 町
char[][] town = new char[height][width];
String line = "";
for(int i = 0; i < height; i++){
line = sc.next();
for(int j = 0; j < width; j++){
town[i][j] = line.charAt(j);
}
}
NezumiKozo nezumi = new NezumiKozo();
while(true){
// 町の外に出たら終わり
try{
// 庶民 → 富豪
if(town[y][x] == '.'){
town[y][x] = '*';
nezumi.moveOut();
// 富豪 → 庶民
}else if(town[y][x] == '*'){
town[y][x] = '.';
nezumi.moveIn();
}
}catch(Exception e){
break;
}
switch(nezumi.getDirection()){
case 'U':
y--;
break;
case 'R':
x++;
break;
case 'D':
y++;
break;
case 'L':
x--;
break;
}
}
for(char[] t : town){
System.out.println(t);
}
}
}
class NezumiKozo{
private char direction = 'U';
// お金をあげた(庶民 → 富豪)
public void moveOut(){
switch(direction){
case 'U':
direction = 'R';
break;
case 'R':
direction = 'D';
break;
case 'D':
direction = 'L';
break;
case 'L':
direction = 'U';
break;
}
}
// お金を盗んだ(富豪 → 庶民)
public void moveIn(){
switch(direction){
case 'U':
direction = 'L';
break;
case 'R':
direction = 'U';
break;
case 'D':
direction = 'R';
break;
case 'L':
direction = 'D';
break;
}
}
// 現在の向きを見る
public char getDirection(){
return direction;
}
}
```
## B030:氷のダンジョン
java 経過時間:約 1時間
```java=
import java.util.*;
/*
5 5 縦 横
.###. マップ
#.#.#
##..#
..##.
##..#
3 3 自分の座標
5 移動の回数
U 移動の方向
R
D
L
U
*/
public class Main {
public static void main(String[] args) {
// スキャナ
Scanner sc = new Scanner(System.in);
// 縦横
int height = sc.nextInt();
int width = sc.nextInt();
// マップ
char[][] filed = new char[height][width];
String line = "";
for(int i = 0; i < height; i++){
line = sc.next();
for(int j = 0; j < width; j++){
filed[i][j] = line.charAt(j);
}
}
// 自分の座標
int x = sc.nextInt() - 1;
int y = sc.nextInt() - 1;
// 移動回数
int move = sc.nextInt();
for(int i = 0; i < move; i++){
String direction = sc.next();
while(true){
switch(direction){
case "U":
y--;
break;
case "D":
y++;
break;
case "R":
x++;
break;
case "L":
x--;
break;
}
try{
if(filed[y][x] == '.'){
break;
}
}catch(Exception e){
switch(direction){
case "U":
y++;
break;
case "D":
y--;
break;
case "R":
x--;
break;
case "L":
x++;
break;
}
break;
}
}
}
System.out.println((x + 1) + " " + (y + 1));
}
}
```
## B062:部屋掃除ロボット
java 解答時間: 18分57秒
```java=
import java.util.*;
/*
20 計測する秒数
4 6 縦 横
..##.. マップ
.##.#.
##..#.
.....#
*/
/*
初期状態は左上で右向き
*/
public class Main {
public static void main(String[] args) {
// スキャナ生成
Scanner sc = new Scanner(System.in);
// 計測秒数
int second = sc.nextInt();
// 縦横
int height = sc.nextInt();
int width = sc.nextInt();
// マップ
char[][] room = new char[height][width];
String line = "";
for(int i = 0; i < height; i++){
line = sc.next();
for(int j = 0; j < width; j++){
room[i][j] = line.charAt(j);
}
}
// 汚い床を掃除した数をカウント
int countDirty = 0;
// 掃除ロボの座標
int x = 0;
int y = 0;
// 掃除ロボ生成
Rumba rumba = new Rumba();
// 計測開始
for(int i = 0; i < second; i++){
// 汚い床はカウント
if(room[y][x] == '#'){
countDirty++;
}
// 掃除済み
room[y][x] = 'o';
// 進む
switch(rumba.getDirection()){
case 'U':
y--;
break;
case 'R':
x++;
break;
case 'D':
y++;
break;
case 'L':
x--;
break;
}
// 壁にぶつかった場合
try{
// すでに掃除済みにぶつかった
if(room[y][x] == 'o'){
// もどって
switch(rumba.getDirection()){
case 'U':
y++;
break;
case 'R':
x--;
break;
case 'D':
y--;
break;
case 'L':
x++;
break;
}
// 方向転換
rumba.turn();
// 進む
switch(rumba.getDirection()){
case 'U':
y--;
break;
case 'R':
x++;
break;
case 'D':
y++;
break;
case 'L':
x--;
break;
}
}
}catch(Exception e){
// もどって
switch(rumba.getDirection()){
case 'U':
y++;
break;
case 'R':
x--;
break;
case 'D':
y--;
break;
case 'L':
x++;
break;
}
// 方向転換
rumba.turn();
// 進む
switch(rumba.getDirection()){
case 'U':
y--;
break;
case 'R':
x++;
break;
case 'D':
y++;
break;
case 'L':
x--;
break;
}
}
}
System.out.println(countDirty);
}
}
class Rumba{
private char direction = 'R';
// 向いている方向を返す
public char getDirection(){
return direction;
}
// 方向転換
public void turn(){
switch(direction){
case 'U':
direction = 'R';
break;
case 'R':
direction = 'D';
break;
case 'D':
direction = 'L';
break;
case 'L':
direction = 'U';
break;
}
}
}
```
## B067:タスクの管理
java 解答時間: 33分40秒
```java=
import java.util.*;
/*
3 タスク数
4 8 11 必要日数 開始日 終了日
7 4 15
7 1 20
*/
public class Main {
public static void main(String[] args) {
// スキャナ
Scanner sc = new Scanner(System.in);
// タスク数
int t = sc.nextInt();
// タスク生成
Task[] tasks = new Task[t];
for(int i = 0; i < t; i++){
int nd = sc.nextInt();
int sd = sc.nextInt();
int ed = sc.nextInt();
tasks[i] = new Task(nd, sd, ed);
}
// 経過日
int date = 0;
while(true){
// 日にちが経過
date++;
// 実行できるタスクがあるか確認
for(int i = 0; i < t; i++){
if(tasks[i].checkStart(date) && !tasks[i].checkTask()){
// タスクを進める
tasks[i].addManHours();
break;
}
}
// 終了日をすぎても終わっていないタスクを探す
for(Task task : tasks){
if(!task.checkEnd(date)){
// あった
System.out.println("NO");
return;
}
}
// タスクが終わってるかチェック
boolean check = true;
// タスクがすべて完了したら終了
for(Task task : tasks){
if(!task.checkTask()){
check = false;
}
}
if(check){
System.out.println("YES");
return;
}
}
}
}
class Task{
private int needDays;
private int startDay;
private int endDay;
private int manHours = 0;
public Task(int nD, int sD, int eD){
this.needDays = nD;
this.startDay = sD;
this.endDay = eD;
}
// 終了日を過ぎてもタスクが終わっていなければfalse
public boolean checkEnd(int d){
// まだ終了日が来ていない
if(d < endDay){
return true;
}else{
return checkTask();
}
}
// タスクがクリアされているか
public boolean checkTask(){
return needDays <= manHours;
}
// タスクが進んだ
public void addManHours(){
manHours++;
}
// タスクの経過度合い
public int getManHours(){
return manHours;
}
// 現在日がタスク開始日を過ぎていればtrue
public boolean checkStart(int d){
return startDay <= d;
}
}
```
## B050:有効なチケット
java 解答時間: 26分14秒
```java=
import java.util.*;
/*
7 チケットの枚数
paiza 指定された文字列
sdfpaizaoiu チケットに描かれた暗号
sdfpaizoiu
paxiza
paxizya
ghepaizmakbn
paizzza
abcpadizzzaopq
*/
public class Main {
public static void main(String[] args) {
// スキャナ
Scanner sc = new Scanner(System.in);
// チケットの枚数
int ticket = sc.nextInt();
// 指定された文字列
String str = sc.next().replaceAll(" ","");
// 指定された文字列の文字数
int length = str.length();
// チケットリストを作る
String strTicket = "";
List<String> ticketList = new ArrayList<String>();
for(int i = 0; i < ticket; i++){
// チケットの文字列を入力
strTicket = sc.next().replaceAll(" ","");
ticketList.add(strTicket);
}
// 間に1文字入っている場合の文字列を格納
String strOne = "";
for(String s : ticketList){
// 文字列が含まれている
if(s.contains(str)){
System.out.println("valid");
continue;
}
boolean check = false;
// 間に一文字在るが、含まれている
for(int i = 1; i < length; i++){
strOne = str.substring(0, i) + "." + str.substring(i, length);
if(s.matches(".*" + strOne + ".*")){
check = true;
break;
}
}
if(check){
System.out.println("valid");
}else{
System.out.println("invalid");
}
}
}
}
```
## B031:コインのウラとオモテ (途中)
java 経過時間:30分
```java=
import java.util.*;
/*
3 ボードの長さ
bwb コインの初期値
*/
public class Main {
public static void main(String[] args) {
// スキャナ
Scanner sc = new Scanner(System.in);
// ボードの長さ
int width = sc.nextInt();
// ボード
String line = sc.next().replaceAll(" ","");
char[] boad = new char[width];
for(int i = 0; i < width; i++){
boad[i] = line.charAt(i);
}
// 反転後のボード
char[] afterBoad = new char[width];
afterBoad = boad;
// ゲーム開始
while(true){
boad = afterBoad;
System.out.print(boad);
System.out.print(" ");
System.out.println(afterBoad);
// ボードを端から見る
for(int i = 0; i < width; i++){
for(int j = i + 1; j < width; j++){
// 挟んだらi以上j未満を反転
if(boad[i] == boad[j]){
for(int k = i + 1; k < j; k++){
afterBoad[k] = '+';
}
}
}
}
System.out.print(boad);
System.out.print(" ");
System.out.println(afterBoad);
char first = afterBoad[0];
boolean check = false;
// 反転できなくなるまでやる
for(int i = 0; i < width; i++){
if(first == afterBoad[i]){
first = afterBoad[i];
check = true;
}else{
check = false;
}
}
if(!check){
break;
}
// 全て同じなら抜ける
first = afterBoad[0];
check = true;
for(char c : afterBoad){
if(first != c){
check = false;
break;
}
}
if(check){
break;
}
}
boad = afterBoad;
int countB = 0;
for(char c : boad){
if(c == 'b'){
countB++;
}
}
System.out.println(countB);
}
}
```