text stringlengths 49 983k |
|---|
#include<bits/stdc++.h>
using namespace std;
string bw;
int ans;
int main(){
cin>>bw;
for(int i=1;i<bw.size();i++){
if(bw[i]!=bw[i-1])ans++;
}
cout<<ans<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int cnt=0;
for(int i=0;i<s.size()-1;i++){
if(s[i]!=s[i+1]){
cnt++;
}
}
cout << cnt << endl;
} |
#include<bits/stdc++.h>
using namespace std;
char a[100005];int l,i,ans;
int main(){
scanf("%s",a);
l=strlen(a);
for(i=1;i<l;i++)
if(a[i]!=a[i-1])
ans++;
printf("%d\n",ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;cin>>S;int M=0;
for(int X=1;X<S.size();X++){
if(S[X]!=S[X-1])M++;
}
cout<<M<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;cin>>s;
int sum=0;
for(int i=1;i<s.size();i++)if(s[i]!=s[i-1])sum++;
cout<<sum;
} |
#include<bits/stdc++.h>
using namespace std;
int main(){
int ans = 0, i;
string s;
cin >> s;
for(int i = 1; i < s.size(); i++){
if(s[i-1] != s[i]) ans++;
}
printf("%d\n", ans);
} |
#include <iostream>
using namespace std;
int main(void){
string s;
cin >> s;
char c = s[0];
int sum = 0;
for(char i : s){
if(i != c){
sum++;
c = i;
}
}
cout << sum << endl;
} |
#include<bits/stdc++.h>
using namespace std;
string a;
int ans=0;
int main() {
cin>>a;
int len=a.size();
for(int i=0;i<len-1;i++) if(a[i]!=a[i+1]) ans++;
cout<<ans<<endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
ll ans;
int main()
{
cin>>s;
ll len=s.size();
for(int i=1;i<len;i++)
if(s[i]!=s[i-1]) ans++;
cout<<ans;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
string a;
long long b;
int main()
{
cin>>a;
for(int i=1;i<a.length();i++)
if(a[i-1]!=a[i]) b++;
cout<<b;
return 0;
} |
#include <stdio.h>
#include <string.h>
int main()
{
char str[100001];
gets(str);
int len=strlen(str),ans=0,i;
for(i=0;i<len-1;i++)
if(str[i]!=str[i+1])
ans++;
printf("%d\n",ans);
} |
#include <iostream>
using namespace std;
int main(){
string s;
cin >> s;
int ans=0;
for(int i=0; i<(int)s.length()-1; i++){
if(s[i]!=s[i+1]) ans++;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
string a;
cin >> a;
int ans=0;
for (int i=0;i<a.length()-1;i++) if (a[i]!=a[i+1]) ans++;
cout << ans << endl;
} |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
int ans=0;
for(int i=0;i<s.size()-1;i++)
ans+=(s[i]!=s[i+1]);
cout<<ans<<'\n';
return 0;
} |
#include<iostream>
using namespace std;
int main(){
string s; cin >> s;
int ans=0;
for(int i=0;i<s.size()-1;++i){
if(s[i]!=s[i+1]) ans++;
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin>>S;
int sum=0;
for(int i=1;i<S.size();i++){
if(S.at(i)!=S.at(i-1)) sum++;
}
cout<<sum<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
string s;
int ans;
int main()
{
cin>>s;
for(int i=1;i<s.size();i++)
if(s[i]!=s[i-1])
ans++;
printf("%d\n",ans);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main()
{
char c1,c2;int cnt=0;
cin>>c2;
while(cin>>c1)
{
if(c1!=c2) ++cnt;
c2=c1;
}
cout<<cnt<<endl;
return 0;
} |
#include<iostream>
#include<algorithm>
using namespace std;
string s;
signed main(){return cin>>s,s.erase(unique(s.begin(),s.end()),s.end()),cout<<s.size()-1<<endl,0;} |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string a;
int i=0;
cin>>a;
for(int k=1;k<a.size();k++)
{
if(a[k-1]!=a[k])i++;
}
cout<<i<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;cin>>s;
int change=0;
for(int i=0;i<s.size()-1;i++)if(s[i]!=s[i+1])change++;
cout<<change<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
int ans=0;
cin>>s;
for(int i=1;i<s.size();i++){
if(s[i]!=s[i-1]){
ans++;
}
}
cout<<ans<<endl;
} |
#include <iostream>
using namespace std;
int main()
{
string a;
int lena,sum=0;
cin>>a;
lena=a.length();
for(int i=0;i<lena-1;i++)
if(a[i]!=a[i+1])
sum++;
cout<<sum<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
string s;
int temp;
int main()
{
cin>>s;
int t=s.length();
for(int i=0;i<t-1;i++)
if(s[i]!=s[i+1])temp++;
cout<<temp;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string n;
int i,j=0;
cin>>n;
for(i=0;i<n.size();i++)
{
if(n[i]!=n[i+1])
{
j++;
}
}
cout<<j-1<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin>>S;
char ch=S.at(0);
int j=0;
for(char &c:S)
if(c!=ch){
j++;
ch=c;
}
cout<<j<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
int zs;
string st;
int main()
{
cin>>st;
for (int i=0;i<st.size()-1;i++)
if (st[i]!=st[i+1]) zs++;
cout<<zs<<endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
int i,j,cnt;
string s;
cin>>s;
cnt=0;
for(i=0;i<s.size()-1;i++){
if(s[i+1]!=s[i])cnt++;
}
cout<<cnt;
} |
#include<bits/stdc++.h>
using namespace std;
char a[100100];
int ans=0;
int main()
{
gets(a);
int n=strlen(a);
for(int i=1;i<=n;i++)if(a[i]!=a[i-1])ans++;
cout<<ans-1<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
int ans=0;
cin>>s;
int len=s.length();
for(int i=1;i<len;i++)
if(s[i]!=s[i-1])
ans++;
cout<<ans<<endl;
return 0;
} |
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
string s;
cin>>s;
int n=s.size();
int a=0;
for(int i=1;i<n;i++)a+=s[i]!=s[i-1];
cout<<a<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
string st;
int ans;
int main()
{
cin>>st;
for(int i=1;i<st.size();i++)
if(st[i]!=st[i-1])
ans++;
printf("%d\n",ans);
return 0;
} |
#include<bits/stdc++.h>
char a[100001];
int main(){
gets(a);
int i,sum=0;
for(i=1;i<strlen(a);i++)
if(a[i]!=a[i-1])
sum++;
printf("%d\n",sum);
return 0;
} |
#include<cstdio>
using namespace std;
char s[100001];
int main(){
scanf("%s",s+1);
int n=0,m=0;for(;s[n+1];n++);
for(int i=1;i<=n;i++)if(s[i]!=s[i-1])m++;
printf("%d",m-1);
} |
#include<iostream>
using namespace std;
int main(){
string s;
cin >> s;
char c=s[0];
int ans=0;
for(int i=1;i<s.length();i++){
if(s[i]!=c){
ans++;
c=s[i];
}
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int s=0;
string f;
cin>>f;
for(int i=1;i<f.length();i++)
{
if(f[i-1]!=f[i])s++;
}
cout<<s;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int ans = 0;
cin >> s;
for(int i = 0;i < s.size()-1;i++){
if(s.at(i) != s.at(i+1)) ans++;
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int sum=0;
string a;
cin>>a;
int l=a.length();
for(int i=0;i<=l-2;i++)
if(a[i]!=a[i+1])
sum++;
cout<<sum<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
char s[100001];
int ans=0;
int main()
{
gets(s);
for(int i=1;i<strlen(s);i++){
if(s[i]!=s[i-1])
ans++;
}
cout<<ans<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
int ans=0;
int main() {
string s;
cin>>s;
for(int i=1; i<=s.length()-1; i++) {
if(s[i]!=s[i-1]) ans++;
}
cout<<ans<<endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin >> s;
int n = s.length();
int cnt = 0;
for(int i = 1; i < n; i++) {
if(s[i] != s[i-1]) cnt++;
}
cout << cnt;
}
|
#include<bits/stdc++.h>
using namespace std;
int i,ans=0;
int main(){
string a;
cin>>a;
for(i=0;i<a.size();i++){
if(a[i]!=a[i-1]) ans++;
}
cout<<ans-1;
return 0;
} |
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int x=0;
char s[100001];
cin >> s;
for(int i=1;i<strlen(s);i++)
{
if(s[i] != s[i-1])
{
x++;
}
}
cout << x;
} |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string at;
int ct=0;
cin>>at;
for(int i=0;i<at.size()-1;i++) if(at[i]!=at[i+1]) ct++;
cout<<ct<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;cin>>S;
int cnt=0;
char rc=S[0];
for(int i=1;i<S.size();i++){
if(rc!=S[i])cnt++;
rc=S[i];
}
cout<<cnt<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;cin>>S;int N=0;
for(int i=1;i<S.size();i++)if(S.at(i-1)!=S.at(i))N++;
cout<<N<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int cnt=0;
string s;
cin>>s;
for(int i=0;i<s.size()-1;i++){
if(s[i]!=s[i+1]){
cnt++;
}
}
cout<<cnt;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
string s;
int ans;
int main()
{
cin>>s;
int i;
int l=s.size();
for(i=1;i<l;i++){
if(s[i-1]!=s[i])ans+=1;
}
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int ans = 0;
for (int i = 0; i < S.size()-1; i++) {
ans += S[i] != S[i+1];
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin >> S;
int ans=0;
for (int i=1;i<S.size();i++){
if (S[i-1]!=S[i]){
ans++;
}
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
int main(){
string s;cin>>s;
int ans=0;
REP(i,s.size()-1) if(s.at(i)!=s.at(i+1)) ans++;
cout<<ans;
} |
#include<bits/stdc++.h>
using namespace std;
string s;
int cnt;
int main()
{
cin>>s;
for(int i=0;i<s.size()-1;i++)
{
if(s[i]!=s[i+1])
{
cnt++;
}
}
cout<<cnt<<endl;
return 0;
} |
#include<iostream>
#include<string>
using namespace std;
string a;
int n;
int main()
{
cin>>a;
for(int i=0;i<a.size();i++)
{
if(a[i]!=a[i-1]) n++;
}
cout<<n-1<<endl;
return 0;
} |
#include<iostream>
#include<cstdio>
using namespace std;
long long s,n;
string st;
int main()
{
cin>>st;n=st.size();
for(int i=0;i<n-1;i++)
{
if(st[i]!=st[i+1])s++;
}
cout<<s;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int cnt = 0;
for (int i = 1; i < S.size(); i++) if (S.at(i - 1) != S.at(i)) cnt++;
cout << cnt << "\n";
} |
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };
int main() {
vector<string>sts;
string st;
while (cin >> st) {
sts.emplace_back(st);
}
int asize = sts.size() / 2 + 4;
vector<vector<vector<int>>>walls(asize, vector<vector<int>>(asize, vector<int>(4)));
for (int i = 0; i < sts.size() / 2+1; ++i) {
for (int j = 0; j < sts[2*i].size(); ++j) {
int num = sts[2*i][j] == '1';
walls[i+1][j+2][1] = num;
walls[i + 2][j + 2][3] = num;
}
}
for (int i = 0; i < sts.size() / 2; ++i) {
for (int j = 0; j < sts[2 * i+1].size(); ++j) {
int num = sts[2 * i+1][j] == '1';
walls[i +2][j+1][2] = num;
walls[i + 2][j + 2][0] = num;
}
}
vector<int>ways;
int nway = 2;
int nx = 2;
int ny = 1;
while (1) {
assert(walls[ny][nx][(nway +3) % 4]);
if (walls[ny][nx][nway]) {
ways.emplace_back(nway);
nway = (nway + 1) % 4;
}
else if (walls[ny + dy[nway]][nx + dx[nway]][(nway + 3) % 4]) {
ways.emplace_back(nway);
ny += dy[nway];
nx += dx[nway];
if (ny == 1 && nx == 2)break;
}
else if (walls[ny + dy[nway] + dy[(nway + 3) % 4]][nx + dx[nway] + dx[(nway + 3) % 4]][(nway + 2) % 4]) {
ways.emplace_back(nway);
//ways.emplace_back((nway + 3) % 4);
ny += dy[nway] + dy[(nway + 3) % 4];
nx += dx[nway] + dx[(nway + 3) % 4];
nway = (nway + 3) % 4;
if (ny == 1 && nx == 2)break;
}
else {
ways.emplace_back(nway);
//ways.emplace_back((nway + 3) % 4);
//ways.emplace_back((nway + 2) % 4);
ny += dy[(nway + 3) % 4];
nx += dx[(nway + 3) % 4];
nway = (nway + 2) % 4;
if (ny == 1 && nx == 2)break;
}
if (nx == 2 && ny == 1)break;
}
string mp;
mp = "LDRU";
for (auto w : ways) {
cout << mp[w];
}
cout << endl;
return 0;
} |
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
char WX[7][6],WY[6][7];
for(int i=0;i<7;i++){
for(int j=0;j<6;j++){
WX[i][j] = 0;
WY[j][i] = 0;
}
}
for(int i=1;i<5;i++) cin >> WX[i][1];
for(int i=1;i<6;i++) cin >> WY[1][i];
for(int i=1;i<5;i++) cin >> WX[i][2];
for(int i=1;i<6;i++) cin >> WY[2][i];
for(int i=1;i<5;i++) cin >> WX[i][3];
for(int i=1;i<6;i++) cin >> WY[3][i];
for(int i=1;i<5;i++) cin >> WX[i][4];
for(int i=1;i<6;i++) cin >> WY[4][i];
for(int i=1;i<5;i++) cin >> WX[i][5];
int NX = 1;
int NY = 1;
char s = 'R';
while(1){
if(s=='R'){
if(WY[NY-1][NX]=='1'){ s = 'U'; NY--; cout << s;}
else if(WX[NX][NY]=='1'){ NX++; cout << s;}
else if(WY[NY][NX]=='1'){ s = 'D'; NY++; cout << s;}
else s = 'L';
}
else if(s=='L'){
if(WY[NY][NX]=='1'){ s = 'D'; NY++; cout << s;}
else if(WX[NX-1][NY]=='1'){ NX--; cout << s;}
else if(WY[NY-1][NX]=='1'){ s = 'U'; NY--; cout << s;}
else s = 'R';
}
else if(s=='U'){
if(WX[NX-1][NY]=='1'){ s = 'L'; NX--; cout << s;}
else if(WY[NY-1][NX]=='1'){ NY--; cout << s;}
else if(WX[NX][NY]=='1'){ s = 'R'; NX++; cout << s;}
else s = 'D';
}
else if(s=='D'){
if(WX[NX][NY]=='1'){ s = 'R'; NX++; cout << s;}
else if(WY[NY][NX]=='1'){ NY++; cout << s;}
else if(WX[NX-1][NY]=='1'){ s = 'L'; NX--; cout << s;}
else s = 'U';
}
if(NX*NY==1) break;
}
cout << endl;
} |
// AOL q0037
// YAMADA Terushige
// 2013.4.12
#include<iostream>
using namespace std;
int grid[5][5][4];
int main(){
enum Direc {L,U,R,D};
string s;
int i,j,k,d;
for(i=0;i<4;i++){
cin >> s;
for(j=0;j<4;j++){
grid[i][j][R]=grid[i][j+1][L]=s[j]-'0';
}
cin >> s;
for(j=0;j<5;j++){
grid[i][j][D]=grid[i+1][j][U]=s[j]-'0';
}
}
cin >> s;
for(j=0;j<4;j++){
grid[i][j][R]=grid[i][j+1][L]=s[j]-'0';
}
i=0;j=1;
d=R;cout <<'R';
while(i!=0 || j!=0){
d=(d+2)%4;
for(k=0;k<4;k++){
d=(d+1)%4;
if(grid[i][j][d]==1)break;
}
switch(d){
case L:
cout << 'L';j--;
break;
case U:
cout << 'U';i--;
break;
case R:
cout << 'R';j++;
break;
case D:
cout << 'D';i++;
break;
}
}
cout << endl;
}
|
#include <stdio.h>
#include <string>
using namespace std;
int main(void) {
int row, col;
char direction = 'R';
//char str[11][6] = { "00000","1111","00001","0110","01011","0010","01111","0010","01001","0111","00000" };
char str[11][6] = {'\0'};
for (int i = 1; i < 10; i++) {
scanf("%s", str[i]);
}
printf("R");
row = 1;
col = 1;
while (1) {
switch (direction) {
case 'U':
//left
if (col != 0 && str[row][col - 1] == '1') {
direction = 'L';
col = col - 1;
printf("L");
}
//up
else if (row != 1 && str[row - 1][col] == '1') {
direction = 'U';
row = row - 2;
printf("U");
}
//right
else if (col != 4 && str[row][col] == '1') {
direction = 'R';
col = col + 1;
printf("R");
}
//down
else if (row != 9 && str[row + 1][col] == '1') {
direction = 'D';
row = row + 2;
printf("D");
}
break;
case 'D':
//right
if (col != 4 && str[row][col] == '1') {
direction = 'R';
col = col + 1;
printf("R");
}
//down
else if (row != 9 && str[row + 1][col] == '1') {
direction = 'D';
row = row + 2;
printf("D");
}
//left
else if (col != 0 && str[row][col - 1] == '1') {
direction = 'L';
col = col - 1;
printf("L");
}
//up
else if (row != 1 && str[row - 1][col] == '1') {
direction = 'U';
row = row - 2;
printf("U");
}
break;
case 'L':
//down
if (row != 9 && str[row + 1][col] == '1') {
direction = 'D';
row = row + 2;
printf("D");
}
//left
else if (col != 0 && str[row][col - 1] == '1') {
direction = 'L';
col = col - 1;
printf("L");
}
//up
else if (row != 1 && str[row - 1][col] == '1') {
direction = 'U';
row = row - 2;
printf("U");
}
//right
else if (col != 4 && str[row][col] == '1') {
direction = 'R';
col = col + 1;
printf("R");
}
break;
case 'R':
//up
if (row != 1 && str[row - 1][col] == '1') {
direction = 'U';
row = row - 2;
printf("U");
}
//right
else if (col != 4 && str[row][col] == '1') {
direction = 'R';
col = col + 1;
printf("R");
}
//down
else if (row != 9 && str[row + 1][col] == '1') {
direction = 'D';
row = row + 2;
printf("D");
}
//left
else if (col != 0 && str[row][col - 1] == '1') {
direction = 'L';
col = col - 1;
printf("L");
}
break;
}
if (row == 1 && col == 1) {
printf("L");
break;
}
}
printf("\n");
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
bool map[11][11] = { false };
int x = 1, y = 1, vec = 0;
int dir[4] = {3, 0, 1, 2};
int dx[2][4] = { {1, 0, -1, 0}, {2, 0, -2, 0} };
int dy[2][4] = { {0, 1, 0, -1}, {0, 2, 0, -2} };
string opr[] = { "R", "D", "L", "U" };
void solve() {
int tmp = 0;
bool next = true;
while (next) {
for (int i = 0; i < 4; i++) {
tmp = (dir[vec] + i) % 4;
if (map[y + dy[0][tmp]][x + dx[0][tmp]]) {
y += dy[1][tmp];
x += dx[1][tmp];
vec = tmp;
cout << opr[tmp];
if (x == 1 && y == 1) next = false;
break;
}
}
}
cout << endl;
}
int main() {
string str;
int tmp;
for (int i = 0; i < 9; i++) {
cin >> str;
if (i % 2 == 0) {
for (int j = 0; j < 4; j++) {
tmp = str[j] - '0';
if (tmp == 1) {
map[(i / 2) * 2 + 1][j * 2 + 1] = true;
map[(i / 2) * 2 + 1][(j + 1) * 2] = true;
map[(i / 2) * 2 + 1][(j + 1) * 2 + 1] = true;
}
}
} else {
for (int j = 0; j < 5; j++) {
tmp = str[j] - '0';
if (tmp == 1) {
map[(i / 2 + 1) * 2][j * 2 + 1] = true;
map[(i / 2 + 1) * 2 + 1][j * 2 + 1] = true;
}
}
}
}
solve();
return 0;
} |
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
using namespace std;
char x[11][11];
void search(int i, int j, int direction);
int main () {
for(int i=0; i<11; i++){
for(int j=0; j<11; j++){
x[i][j]='0';
}
}
while(cin
>>x[1][2]>>x[1][4]>>x[1][6]>>x[1][8]
>>x[2][1]>>x[2][3]>>x[2][5]>>x[2][7]>>x[2][9]
>>x[3][2]>>x[3][4]>>x[3][6]>>x[3][8]
>>x[4][1]>>x[4][3]>>x[4][5]>>x[4][7]>>x[4][9]
>>x[5][2]>>x[5][4]>>x[5][6]>>x[5][8]
>>x[6][1]>>x[6][3]>>x[6][5]>>x[6][7]>>x[6][9]
>>x[7][2]>>x[7][4]>>x[7][6]>>x[7][8]
>>x[8][1]>>x[8][3]>>x[8][5]>>x[8][7]>>x[8][9]
>>x[9][2]>>x[9][4]>>x[9][6]>>x[9][8]
)
{
search(1, 1, 1);
cout<<endl;
}
return 0;
}
void search(int i, int j, int direction){
while(1){
char around[4];
around[0]=x[i-1][j];
around[1]=x[i][j+1];
around[2]=x[i+1][j];
around[3]=x[i][j-1];
char output[4]={'U','R','D','L'};
int next[4]={0,1,2,3};
int move[4][2]={0};
if(around[0]=='1'){
move[0][0]=i-2;move[0][1]=j;
}
if(around[1]=='1'){
move[1][0]=i;move[1][1]=j+2;
}
if(around[2]=='1'){
move[2][0]=i+2;move[2][1]=j;
}
if(around[3]=='1'){
move[3][0]=i;move[3][1]=j-2;
}
for(int k=0; k<4; k++){
int temp = (direction+3+k)%4;
if(around[temp]=='1'){
direction=next[temp];
i=move[temp][0];
j=move[temp][1];
cout<<output[temp];
break;
}
}
if(i==1&&j==1){
break;
}
}
} |
#include<bits/stdc++.h>
using namespace std;
string side[4],Longitudinal[5];
int mox[2][2]={{1,-1},{0,-1}},moy[2][2]={{-1,1},{-1,0}};
char str[5]="URDL";
void serch(int x,int y,int then)
{
if(then==-1)then=3;
if(x==0&&y==0){
cout<<endl;
exit(0);
}
for(int i=0;i<4;i++){
int now=(then+i)%4;
if(now%2==0){
if(y+moy[0][now/2]<5&&y+moy[0][now/2]>-1&&side[y+moy[1][now/2]][x]=='1'){
cout<<str[now];
serch(x,y+moy[0][now/2],now-1);
}
}
else{
if(x+mox[0][now/2]<5&&x+mox[0][now/2]>-1&&Longitudinal[y][x+mox[1][now/2]]=='1'){
cout<<str[now];
serch(x+mox[0][now/2],y,now-1);
}
}
}
}
int main()
{
for(int i=0;i<4;i++)cin>>Longitudinal[i]>>side[i];
cin>>Longitudinal[4];
cout<<"R";
serch(1,0,0);
} |
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
int p[5][5][4];
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++ )
for (int k = 0; k < 4; k++) p[i][j][k] = 0;
string s;
for (int i = 0; i < 4; i++) {
cin >> s;
for (int j = 0; j < 4; j++) {
if (s[j] == '1') {
p[i][j][1] = p[i][j+1][3] = 1;
}
}
cin >> s;
for (int j = 0; j < 5; j++) {
if (s[j] == '1') {
p[i][j][2] = p[i+1][j][0] = 1;
}
}
}
cin >> s;
for (int j = 0; j < 4; j++) {
if (s[j] == '1') {
p[4][j][1] = p[4][j+1][3] = 1;
}
}
string DIR = "URDL";
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int px = 0, py = 1, dir = 1;
cout << "R";
int q = 0;
while ((px != 0 || py != 0) && q++ < 40) {
for (int i = 0; i < 4; i++) {
if (p[px][py][(((dir + 3) % 4) + i) % 4] == 1) {
dir = (((dir + 3) % 4) + i) % 4;
px += dx[dir];
py += dy[dir];
cout << DIR[dir];
break;
}
}
}
cout << endl;
return 0;
} |
#include <iostream>
using namespace std;
//R:0 L:1 U:2 D:3
int map[11][7];
int type;
int x=2,y=1;
char a[4],b[5];
void init(){
for(int i=1;i<=9;i++){
if(i%2){
cin>>a;
for(int n=0;n<4;n++)map[i][n+1]=char(a[n])-'0';
}
else{
cin>>b;
for(int m=0;m<5;m++)map[i][m+1]=char(b[m])-'0';
}
}
}
void Right(){
if(map[y-1][x])type=2, y-=2, cout<<'U';
else if(map[y][x])type=0, x+=1, cout<<'R';
else if(map[y+1][x])type=3, y+=2, cout<<'D';
else type=1, x-=1, cout<<'L';
}
void Left(){
if(map[y+1][x])type=3, y+=2, cout<<'D';
else if(map[y][x-1])type=1, x-=1, cout<<'L';
else if(map[y-1][x])type=2, y-=2, cout<<'U';
else type=0, x+=1, cout<<'R';
}
void Up(){
if(map[y][x-1])type=1, x-=1, cout<<'L';
else if(map[y-1][x])type=2, y-=2, cout<<'U';
else if(map[y][x])type=0, x+=1, cout<<'R';
else type=3, y+=2, cout<<'D';
}
void Down(){
if(map[y][x])type=0, x+=1, cout<<'R';
else if(map[y+1][x])type=3, y+=2, cout<<'D';
else if(map[y][x-1])type=1, x-=1, cout<<'L';
else type=2, y-=2, cout<<'U';
}
void solve(){
while(!(x==1&&y==1)){
switch(type){
case 0:Right();
break;
case 1:Left();
break;
case 2:Up();
break;
case 3:Down();
break;
default: return;
}
}
}
int main(){
init();
cout<<'R';
solve();
cout<<"\n";
return 0;
} |
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
typedef pair<int,int> P;
#define pb push_back
#define fi first
#define sec second
int angle=0;
int edge[6][6][4]={0};
vector<int> ans;
P now;
P nextpoint(P t,int angl)
{
P f;
f.fi=t.fi;
f.sec=t.sec;
if(angl==0)
{
f.sec++;
}
if(angl==1)
{
f.fi++;
}
if(angl==2)
{
f.sec--;
}
if(angl==3)
{
f.fi--;
}
return f;
}
void output(int n)
{
if(n==0)
{
cout << 'R';
}
else if(n==1)
{
cout << 'D';
}
else if(n==2)
{
cout << 'L';
}
else
{
cout << 'U';
}
return ;
}
void step()
{
int tmp;
int ans;
tmp=(angle+4-1)%4;
while(1)
{
if(edge[now.fi][now.sec][tmp])break;
tmp=(tmp+1)%4;
}
angle=tmp;
P r;
r.fi=nextpoint(now,angle).fi;
r.sec=nextpoint(now,angle).sec;
now.fi=r.fi;
now.sec=r.sec;
return ;
}
int main()
{
now.fi=1;now.sec=1;
for(int i=1;i<=9;i++)
{
if(i%2==1)
{
string s;
cin >> s;
for(int j=0;j<4;j++)
{
edge[(i+1)/2][j+1][0]=s[j]-'0';
edge[(i+1)/2][j+2][2]=s[j]-'0';
}
}
else
{
string s;
cin >> s;
for(int j=0;j<5;j++)
{
edge[i/2][j+1][1]=s[j]-'0';
edge[i/2+1][j+1][3]=s[j]-'0';
}
}
}
while(1)
{
step();
ans.pb(angle);
if(now.fi==1&&now.sec==1)
{
break;
}
}
for(int i=0;i<ans.size();i++)
{
output(ans[i]);
}
cout << endl;
return 0;
} |
#include <iostream>
#include <string>
using namespace std;
int d;
int x, y;
bool data[9][5];
int main(){
for(int i=0;i<9;i++){
for(int j=0;j<5;j++){
data[i][j]=false;
}
}
for(int i=0;i<9;i++){
for(int j=0;j<=5;j++){
char c;
scanf("%c", &c);
if(c=='\n') break;
if(c=='1') data[i][j]=true;
}
}
x=0;
y=0;
d=0;
for(int i=0;;i++, d++){
// printf("(%d,%d,%d)\n", x, y, d);
if(d==4) d=0;
if(d==0){
if(y==0) continue;
if(data[2*(y-1)+1][x]){
cout << 'U';
y--;
d=2;
}
}else if(d==1){
if(x==4) continue;
if(data[2*y][x]){
cout << 'R';
x++;
d=-1;
}
}else if(d==2){
if(y==4) continue;
if(data[2*y+1][x]){
cout << 'D';
y++;
d=0;
}
}else if(d==3){
if(x==0) continue;
if(data[2*y][x-1]){
cout << 'L';
x--;
d=1;
}
}
if(y==0 && x==0) break;
}
cout << endl;
return 0;
} |
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int field[6][6][4] = {0},p[3];
int x,y;
for(int i=0; i<9; i++){
if(i%2 == 0){
for(int j=0; j<4; j++){
int n;
scanf("%1d",&n);
field[j+1][i/2][2] = n;
field[j+1][i/2+1][0] = n;
}
}
else{
for(int j=0; j<5; j++){
int n;
scanf("%1d",&n);
field[j][i/2+1][1] = n;
field[j+1][i/2+1][3] = n;
}
}
}
p[0] = 1;p[1] = 0; p[2] = 1;
for(;;){
if(p[2] == 0){
if(field[p[0]][p[1]][1] == 1){
cout<<"U";
if(field[p[0]][p[1]][0] == 1){p[2] = 3;}
else{p[1]--;}
}
else if(field[p[0]][p[1]][1] == 0){p[2] = 1;p[0]++;}
}
else if(p[2] == 1){
if(field[p[0]][p[1]][2] == 1){
cout<<"R";
if(field[p[0]][p[1]][1] == 1){p[2] = 0;}
else{p[0]++;}
}
else if(field[p[0]][p[1]][2] == 0){p[2] = 2;p[1]++;}
}
else if(p[2] == 2){
if(field[p[0]][p[1]][3] == 1){
cout<<"D";
if(field[p[0]][p[1]][2] == 1){p[2] = 1;}
else{p[1]++;}
}
else if(field[p[0]][p[1]][3] == 0){p[2] = 3;p[0]--;}
}
else if(p[2] == 3){
if(field[p[0]][p[1]][0] == 1){
cout<<"L";
if(field[p[0]][p[1]][3] == 1){p[2] = 2;}
else{p[0]--;}
}
else if(field[p[0]][p[1]][0] == 0){p[2] = 0;p[1]--;}
}
if(p[0] == 1 && p[1] == 0){cout <<endl;break;}
}
} |
#include <string>
#include <iostream>
using namespace std;
int dir[] = { 0, 1, 0, -1 };
string e = "RDLU";
string s[9]; bool d[6][6][4];
int main() {
for (int i = 0; i < 9; i++) cin >> s[i];
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 4; j++) {
if (s[i * 2][j] == '1') d[i][j + 1][1] = d[i + 1][j + 1][3] = true;
}
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
if (s[i * 2 + 1][j] == '1') d[i + 1][j][0] = d[i + 1][j + 1][2] = true;
}
}
string ret = "R";
int x = 0, y = 1, dr = 0;
while (true) {
if (d[x][y][dr]) dr = (dr + 3) & 3, ret += e[dr];
else {
x += dir[dr], y += dir[dr ^ 1];
if (x == 0 && y == 1) break;
int cnt = 0;
while (!d[x][y][(dr + 1) & 3]) {
dr = (dr + 1) & 3;
x += dir[dr], y += dir[dr ^ 1];
if (x == 0 && y == 1) break;
}
if (x == 0 && y == 1) break;
ret += e[dr];
}
}
cout << ret << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
struct P {
bool r, d, l, u;
P() { r = d = l = u = false; }
};
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(10);
string s;
P p[5][5];
for (int i = 0; i < 9; i++) {
cin >> s;
if (i & 1) {
for (int j = 0; j < 5; j++) {
if (s[j] == '1') p[i / 2][j].d = p[i / 2 + 1][j].u = true;
}
} else {
for (int j = 0; j < 4; j++) {
if (s[j] == '1') p[i / 2][j].r = p[i / 2][j + 1].l = true;
}
}
}
string ans = "R";
int y = 0, x = 1, d = 0;
while (!(y == 0 && x == 0)) {
if (d == 0) {
if (p[y][x].u) y--, d = 3, ans += 'U';
else if (p[y][x].r) x++, d = 0, ans += 'R';
else if (p[y][x].d) y++, d = 1, ans += 'D';
else x--, d = 2, ans += 'L';
} else if (d == 1) {
if (p[y][x].r) x++, d = 0, ans += 'R';
else if (p[y][x].d) y++, d = 1, ans += 'D';
else if (p[y][x].l) x--, d = 2, ans += 'L';
else y--, d = 3, ans += 'U';
} else if (d == 2) {
if (p[y][x].d) y++, d = 1, ans += 'D';
else if (p[y][x].l) x--, d = 2, ans += 'L';
else if (p[y][x].u) y--, d = 3, ans += 'U';
else x++, d = 0, ans += 'R';
} else {
if (p[y][x].l) x--, d = 2, ans += 'L';
else if (p[y][x].u) y--, d = 3, ans += 'U';
else if (p[y][x].r) x++, d = 0, ans += 'R';
else y++, d = 1, ans += 'D';
}
}
cout << ans << endl;
return 0;
}
|
#include <iostream>
using namespace std;
struct point {
int left;
int down;
int right;
int up;
};
void move(point able[5][5], int& x, int& y, int& direction){
switch(direction){
case 0:
if(able[y][x].down){
y++;
direction = 3;
cout << "D";
}else if(able[y][x].left){
x--;
direction = 0;
cout << "L";
}else if(able[y][x].up){
y--;
direction = 1;
cout << "U";
}else if(able[y][x].right){
x++;
direction = 2;
cout << "R";
}
break;
case 1:
if(able[y][x].left){
x--;
direction = 0;
cout << "L";
}else if(able[y][x].up){
y--;
direction = 1;
cout << "U";
}else if(able[y][x].right){
x++;
direction = 2;
cout << "R";
}else if(able[y][x].down){
y++;
direction = 3;
cout << "D";
}
break;
case 2:
if(able[y][x].up){
y--;
direction = 1;
cout << "U";
}else if(able[y][x].right){
x++;
direction = 2;
cout << "R";
}else if(able[y][x].down){
y++;
direction = 3;
cout << "D";
}else if(able[y][x].left){
x--;
direction = 0;
cout << "L";
}
break;
case 3:
if(able[y][x].right){
x++;
direction = 2;
cout << "R";
}else if(able[y][x].down){
y++;
direction = 3;
cout << "D";
}else if(able[y][x].left){
x--;
direction = 0;
cout << "L";
}else if(able[y][x].up){
y--;
direction = 1;
cout << "U";
}
}
}
int main(){
int direction = 3;
int x = 0, y = 0;
point able[5][5];
char c;
for(int i = 0; i < 5; i++)
for(int j = 0; j < 5; j++){
able[i][j].left = 0;
able[i][j].right = 0;
able[i][j].down = 0;
able[i][j].up = 0;
}
for(int i = 0; i < 5; i++){
for(int j = 0; j < 4; j++){
cin >> c;
if(c == '1'){
able[i][j].right = 1;
able[i][j+1].left = 1;
}
}
if(i == 4) break;
for(int j = 0; j < 5; j++){
cin >> c;
if(c == '1'){
able[i][j].down = 1;
able[i+1][j].up = 1;
}
}
}
move(able, x, y, direction);
while(x != 0 || y != 0){
move(able, x, y, direction);
}
cout << endl;
return 0;
} |
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int field[6][6] = {0},a,x = 1,y = 0,t = 1;
for(int i=0; i<5; i++){
for(int j=0; j<4; j++){
scanf("%1d",&a);
field[j+1][i]+=(a<<2);
field[j+1][i+1]+=(a<<0);
}
if(i<4){
for(int j=0; j<5; j++){
scanf("%1d",&a);
field[j][i+1]+=(a<<1);
field[j+1][i+1]+=(a<<3);
}
}
}
for(;;){
if(t == 0){
if(field[x][y]&2){
cout <<"U";
if(field[x][y]&1){t = 3;}
else{y--;}
}
else{x++;t = 1;}
}
else if(t == 1){
if(field[x][y]&4){
cout <<"R";
if(field[x][y]&2){t = 0;}
else{x++;}
}
else{y++;t = 2;}
}
else if(t == 2){
if(field[x][y]&8){
cout <<"D";
if(field[x][y]&4){t = 1;}
else{y++;}
}
else{x--;t = 3;}
}
else if(t == 3){
if(field[x][y]&1){
cout <<"L";
if(field[x][y]&8){t = 2;}
else{x--;}
}
else{y--;t = 0;}
}
if(!x && !y){break;}
}
cout <<endl;
return 0;
} |
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
#define RIGHT 0
#define DOWN 1
#define LEFT 2
#define UP 3
int main(){
bool cross[5][5][4]; // x,y,dir
int px=0, py=0, dir = RIGHT;
int d[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};
string str;
memset( cross, 0, sizeof(cross) );
for( int i=0; i<4; i++ ){
getline( cin, str );
for( int j=0; j<4; j++ ){
cross[j][i][RIGHT] = cross[j+1][i][LEFT] = (str[j]=='1');
}
getline( cin, str );
for( int j=0; j<5; j++ ){
cross[j][i][DOWN] = cross[j][i+1][UP] = (str[j]=='1');
}
}
getline( cin, str );
for( int j=0; j<4; j++ ){
cross[j][4][RIGHT] = cross[j+1][4][LEFT] = (str[j]=='1');
}
do{
for( int i=0; i<4; i++ ){
if( cross[px][py][(dir+3+i)%4] ){
dir = (dir+3+i)%4;
px += d[dir][0];
py += d[dir][1];
// cout << (dir==RIGHT)?"R":((dir==DOWN)?"D":((dir==LEFT)?"L":"U"));
if( dir == RIGHT ){
cout << 'R';
}else if( dir == DOWN ){
cout << 'D';
}else if( dir == LEFT ){
cout << 'L';
}else if( dir == UP ){
cout << 'U';
}
break;
}
}
}while( px!=0 || py!=0 );
cout << endl;
return 0;
} |
#include<stdio.h>
int f[5][5],i,j,a,y,x,p;
int main()
{
for(;i<9;++i){
char s[6];
scanf("%s",s);
for(j=0;j<4+i%2;++j){
a=s[j]-48;
f[i/2][j]|=a<<(1+i%2);
f[i/2+i%2][j+!(i%2)]|=a<<3-i%2*3;
}
}
do{
do
p=(p+1)%4;
while(!((f[y][x]>>p)&1));
putchar("URDL"[p]);
x+=p?2-p:0;
y+=p==3?0:p-1;
p=(p+2)%4;
}while(y!=0||x!=0||f[0][0]==6&&p==3);
return !puts("");
} |
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
int main() {
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
bool yoko[4][5];
bool tate[5][4];
REP(i,9) {
char x;
if (i%2==0)
REP(j,4) {
cin >> x;
yoko[j][i/2] = (x=='1');
}
else
REP(j,5) {
cin >> x;
tate[j][i/2] = (x=='1');
}
}
int x=0,y=0;
int dir = 0;
char ss[4] = {'R','U','L','D'};
x++;
while(true) {
cout << ss[dir];
if (x==0&&y==0) break;
if (dir == 0) {
if (y>0&&tate[x][y-1]) {
dir = 1;
y--;
} else if (x<4&&yoko[x][y]) {
x++;
} else if (y<4&&tate[x][y]) {
dir = 3;
y++;
} else {
dir = 2;
x--;
}
} else if (dir == 1) {
if (x>0&&yoko[x-1][y]) {
dir = 2;
x--;
} else if (y>0&&tate[x][y-1]) {
y--;
} else if (x<4&&yoko[x][y]) {
dir = 0;
x++;
} else {
dir = 3;
y++;
}
} else if (dir == 2) {
if (y<4&&tate[x][y]) {
dir = 3;
y++;
} else if (x>0&&yoko[x-1][y]) {
x--;
} else if (y>0&&tate[x][y-1]) {
dir = 1;
y--;
} else {
dir = 0;
x++;
}
} else if (dir == 3) {
if (x<4&&yoko[x][y]) {
dir = 0;
x++;
} else if (y<4&&tate[x][y]) {
y++;
} else if (x>0&&yoko[x-1][y]) {
dir = 2;
x--;
} else {
dir = 1;
y--;
}
}
}
cout << endl;
} |
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
vector<string>in(9);
cout<<'R';
rep(i,9)cin>>in[i];
int x=1,y=0;
int to=0;
//int co=0;
while(x||y){
//co++;
//if(co>50)break;
//cout<<x<<" "<<y<<" "<<to<<endl;
if(to==0){
if(y!=0&&in[2*y-1][x]=='1'){
y--;to=3;cout<<'U';
}else if(x!=4&&in[2*y][x]=='1'){
x++;cout<<'R';
}else if(y!=4&&in[2*y+1][x]=='1'){
y++;to=1;cout<<'D';
}else if(x!=0&&in[2*y][x-1]=='1'){
to=2;x--;cout<<'L';
}
}else if(to==1){
if(x!=4&&in[2*y][x]=='1'){
x++;to=0;cout<<'R';
}else if(y!=4&&in[2*y+1][x]=='1'){
y++;to=1;cout<<'D';
}else if(x!=0&&in[2*y][x-1]=='1'){
to=2;x--;cout<<'L';
}else if(y!=0&&in[2*y-1][x]=='1'){
y--;to=3;cout<<'U';
}
}else if(to==2){
if(y!=4&&in[2*y+1][x]=='1'){
y++;to=1;cout<<'D';
}else if(x!=0&&in[2*y][x-1]=='1'){
to=2;x--;cout<<'L';
}else if(y!=0&&in[2*y-1][x]=='1'){
y--;to=3;cout<<'U';
}else if(x!=4&&in[2*y][x]=='1'){
x++;to=0;cout<<'R';
}
}else if(to==3){
if(x!=0&&in[2*y][x-1]=='1'){
to=2;x--;cout<<'L';
}else if(y!=0&&in[2*y-1][x]=='1'){
y--;to=3;cout<<'U';
}else if(x!=4&&in[2*y][x]=='1'){
x++;to=0;cout<<'R';
}else if(y!=4&&in[2*y+1][x]=='1'){
y++;to=1;cout<<'D';
}
}
}
cout<<endl;
} |
#include<iostream>
#include<vector>
#include<map>
#include<string>
using namespace std;
vector<string> mp;
char c[]={'U','R','D','L'};
int dx[]={0,1,0,-1},
dy[]={-1,0,1,0},
fx[]={1,0,-1,0},
fy[]={0,1,0,-1};
void func(int y,int x,int dir){
cout<<c[dir];
if((y==1&&x==0&&dir==0)||(y==1&&x==1&&dir==3)){
cout<<endl;
return;
}
//ツ前
if(mp[dy[dir]+2*y][dx[dir]+2*x]=='1'){
func(y,x,(dir+3)%4);
return;
}
if(mp[y*2+dy[(dir+1)%4]+2*dy[dir]][x*2+dx[(dir+1)%4]+2*dx[dir]]=='1'){
func(y+dy[dir],x+dx[dir],dir);
return ;
}
//
if(mp[2*y+dy[dir]+dy[(dir+1)%4]*2][2*x+dx[dir]+dx[(dir+1)%4]*2]=='1'){
int q=(dir+1)%4;
func(y+dy[dir]+dy[q],x+dx[dir]+dx[q],q);
return;
}
func(y+fy[dir],x+fx[dir],(dir+2)%4);
return;
}
int main(){
string pre;
mp.push_back(" 0 0 0 0 0 ");
for(int i=0;i<9;i++){
string s;
if(i%2==0){
s="0 ";
cin>>pre;
for(int j=0;j<4;j++){
s+=pre[j];
s+=' ';
}
s+='0';
mp.push_back(s);
}
else{
cin>>pre;
s+=' ';
for(int j=0;j<5;j++){
s+=pre[j];
s+=' ';
}
s+=' ';
mp.push_back(s);
}
}
mp.push_back(" 0 0 0 0 0 ");
func(0,1,1);
return 0;
} |
#include<iostream>
using namespace std;
int main()
{
char sidemap[5][4];
char upmap[4][5];
int x=0,y=0;
for(int i=0;i<9;i++)
{
if(i%2==0)
{
for(int j=0;j<4;j++)
cin>>sidemap[i/2][j];
}
else
{
for(int j=0;j<5;j++)
cin>>upmap[i/2][j];
}
}
/*
for(int i=0;i<5;i++,cout<<endl)
for(int j=0;j<4;j++)
{
cout<<sidemap[i][j];
}
for(int i=0;i<4;i++,cout<<endl)
for(int j=0;j<5;j++)
{
cout<<upmap[i][j];
}
*/
char move='R';
do{
//cout<<"now:"<<x<<","<<y;
// cout<<"X,y="<<x<<","<<y<<endl;
//次の移動方向
if(move=='L')
{
if(x<4&&upmap[x][y]=='1')
move='D';
else if(y>0 && sidemap[x][y-1]=='1')
move='L';
else if(x>0 && upmap[x-1][y]=='1')
move='U';
else
move='R';
}
else if(move=='R')
{
if(x>0&&upmap[x-1][y]=='1')
move='U';
else if(y<4 && sidemap[x][y]=='1')
move='R';
else if(x<4&&y<5&&upmap[x][y]=='1')
move='D';
else
move='L';
}
else if(move=='U')
{
if(y>0&&sidemap[x][y-1]=='1')
move='L';
else if(x>0&&upmap[x-1][y]=='1')
move='U';
else if(x<5&&y<4&&sidemap[x][y]=='1')
move='R';
else
move='D';
}
else if(move=='D')
{
if(x<5&&y<4&&sidemap[x][y]=='1')
move='R';
else if(x<4&&upmap[x][y]=='1')
move='D';
else if(y>0&&sidemap[x][y-1]=='1')
move='L';
else
move='U';
}
//次の移動方向
if(move=='L')
{
y--;
}
else if(move=='R')
{
y++;
}
else if(move=='U')
{
x--;
}
else if(move=='D')
{
x++;
}
cout<<move;
/// cout<<endl;
}while(x!=0||y!=0);
cout<<endl;
} |
#include <iostream>
#include <cstdio>
#define LEFT 0
#define UP 1
#define RIGHT 2
#define DOWN 3
#define MIN(X,Y) ((X<Y)?X:Y)
#define MAX(X,Y) ((X>Y)?X:Y)
bool map[5][5][5][5];
int direction=RIGHT;
int pos[2]={0,0};
char nul[5000];
void read(void)
{
for(int y=0;y<4;y++)
{
for(int x=0;x<4;x++)
map[x][y][x+1][y] = (getchar()-'0' == 1);
gets(nul);
for(int x=0;x<5;x++)
map[x][y][x][y+1] = (getchar()-'0' == 1);
gets(nul);
}
for(int x=0;x<4;x++)
map[x][4][x+1][4] = (getchar()-'0' == 1);
return;
}
bool isenable(int x, int y)
{
return ((0<=x)&&(x<=4))&&((0<=y)&&(y<=4));
}
bool isconnect(int dir)
{
int x=pos[0], y=pos[1];
switch(dir) {
case LEFT: x--;
break;
case UP: y--;
break;
case RIGHT: x++;
break;
case DOWN: y++;
break;
}
return (isenable(x,y)&&(map[MIN(pos[0],x)][MIN(pos[1],y)][MAX(pos[0],x)][MAX(pos[1],y)]));
}
void step(int dir)
{
switch(dir) {
case LEFT: pos[0]--; std::cout << "L" << std::flush; direction=LEFT;
break;
case UP: pos[1]--; std::cout << "U" << std::flush; direction=UP;
break;
case RIGHT: pos[0]++; std::cout << "R" << std::flush; direction=RIGHT;
break;
case DOWN: pos[1]++; std::cout << "D" << std::flush; direction=DOWN;
break;
}
return;
}
void move(void)
{
do {
if(isconnect((direction+LEFT-1+4)%4))
step((direction+LEFT-1+4)%4);
else if(isconnect((direction+UP-1+4)%4))
step((direction+UP-1+4)%4);
else if(isconnect((direction+RIGHT-1+4)%4))
step((direction+RIGHT-1+4)%4);
else
step((direction+DOWN-1+4)%4);
//std::cerr << "(x,y):" << pos[0] << "," << pos[1] << std::endl;
}while(!(pos[0]==0 && pos[1]==0));
std::cout << std::endl;
return;
}
int main(void)
{
for(int i=0; i<5; i++)
for(int j=0; j<5; j++)
for(int k=0; j<5; j++)
for(int l=0; j<5; j++)
map[i][j][k][l] = false;
read();
move();
} |
#include <iostream>
#include <string>
using namespace std;
class Dot{
public:
bool d[4];
Dot() {
d[0] = d[1] = d[2] = d[3] = false;
}
};
int main() {
Dot data[5][5];
for(int i = 0; i < 9; i++) {
string str;
getline(cin, str);
int y = i/2;
if(i % 2 == 0) {
for(int j = 0; j < 4; j++) {
if(str[j] == '1') {
data[y][j].d[0] = data[y][j+1].d[2] = true;
}
}
} else {
for(int j = 0; j < 5; j++) {
if(str[j] == '1') {
data[y][j].d[1] = data[y+1][j].d[3] = true;
}
}
}
}
int d[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
int x = 0;
int y = 0;
int dir = 0;
while(1) {
for(int i = 0; i < 4; i++) {
int t = (dir+i+3)%4;
if(data[y][x].d[t]) {
dir = t;
x += d[t][0];
y += d[t][1];
switch(t) {
case 0: cout << 'R'; break;
case 1: cout << 'D'; break;
case 2: cout << 'L'; break;
case 3: cout << 'U'; break;
}
break;
}
}
if(x == 0 && y == 0) {
cout << endl;
break;
}
}
return 0;
} |
#include <stdio.h>
#include <string.h>
#define ROW_BLOCK 4
#define COL_BLOCK 4
#define ROW_NUM (ROW_BLOCK + 2) * 2 - 1
#define COL_NUM (COL_BLOCK + 2) * 2 - 1
#define UP 0
#define RIGHT 1
#define DOWN 2
#define LEFT 3
const char command[5] = "URDL";
const int dy[4] = {-1,0,1,0}, dx[4] = {0,1,0,-1};
const int gy = 1, gx = 1;
int main(void){
int i, j, stage[ROW_NUM][COL_NUM];
memset(stage,0,sizeof(stage));
for(i = 1;i < ROW_NUM - 1;i++){
char str[ROW_BLOCK + 2];
scanf("%s",str);
for(j = 1 + i % 2;j < COL_NUM - 1;j+=2){
stage[i][j] = str[(j - 1) / 2] - '0';
}
}
int nd = RIGHT, nx = 1, ny = 1;
do{
if(stage[ny + dy[nd]][nx + dx[nd]] == 0 && stage[ny + dy[(nd + 3) % 4]][nx + dx[(nd + 3) % 4]] == 0){ // 今向いている方向に壁がなく右手にも壁がなければれば
nd = (nd + 1) % 4;
}else if(stage[ny + dy[(nd + 3) % 4]][nx + dx[(nd + 3) % 4]] == 1){
nd = (nd + 3) % 4;
ny += dy[nd] * 2;
nx += dx[nd] * 2;
printf("%c",command[nd]);
}else{
ny += dy[nd] * 2;
nx += dx[nd] * 2;
printf("%c",command[nd]);
}
/*for(i = 0;i < ROW_NUM;i++){
for(j = 0;j < COL_NUM;j++){
if(ny == i && nx == j){
printf("# ");
}else{
printf("%d ",stage[i][j]);
}
}
printf("\n");
}
while(getchar() != '\n');*/
}while(!((nx == gx) && (ny == gy)));
printf("\n");
return 0;
} |
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;
int main(){
char w1[7][7],w2[7][7],dir;
int x=1,y=1;
for(int i=0;i<7;i++){
for(int j=0;j<7;j++){
w1[i][j] = '0';
w2[i][j] = '0';
}
}
fgets(w1[1],7,stdin);
fgets(w2[1],7,stdin);
fgets(w1[2],7,stdin);
fgets(w2[2],7,stdin);
fgets(w1[3],7,stdin);
fgets(w2[3],7,stdin);
fgets(w1[4],7,stdin);
fgets(w2[4],7,stdin);
fgets(w1[5],7,stdin);
for(int i=5;i>=0;i--){
w1[1][i+1]=w1[1][i];
w2[1][i+1]=w2[1][i];
w1[2][i+1]=w1[2][i];
w2[2][i+1]=w2[2][i];
w1[3][i+1]=w1[3][i];
w2[3][i+1]=w2[3][i];
w1[4][i+1]=w1[4][i];
w2[4][i+1]=w2[4][i];
w1[5][i+1]=w1[5][i];
}
w1[1][0]='0';
w2[1][0]='0';
w1[2][0]='0';
w2[2][0]='0';
w1[3][0]='0';
w2[3][0]='0';
w1[4][0]='0';
w2[4][0]='0';
w1[5][0]='0';/*
for(int i=0;i<7;i++){
for(int j=0;j<7;j++){
if(w1[i][j]=='1') printf("+-");
else printf("+ ");
}
printf("+\n");
for(int j=0;j<7;j++){
if(w2[i][j]=='1') printf("| ");
else printf(" ");
}
printf("\n");
}*/
printf("R");
dir = 'R';
while(1){
if(dir=='R'){
if(w2[x-1][y+1]=='1'){
dir = 'U';
x = x-1;
y = y+1;
}
else if(w1[x][y+1]=='1'){
dir = 'R';
x = x;
y = y+1;
}
else if(w2[x][y+1]=='1'){
dir = 'D';
x = x;
y = y+1;
}
else {
dir = 'L';
x = x;
y = y;
}
}
else if(dir=='L'){
if(w2[x][y]=='1'){
dir = 'D';
x = x;
y = y;
}
else if(w1[x][y-1]=='1'){
dir = 'L';
x = x;
y = y-1;
}
else if(w2[x-1][y]=='1'){
dir = 'U';
x = x-1;
y = y;
}
else {
dir = 'R';
x = x;
y = y;
}
}
else if(dir=='U'){
if(w1[x][y-1]=='1'){
dir = 'L';
x = x;
y = y-1;
}
else if(w2[x-1][y]=='1'){
dir = 'U';
x = x-1;
y = y;
}
else if(w1[x][y]=='1'){
dir = 'R';
x = x;
y = y;
}
else {
dir = 'D';
x = x;
y = y;
}
}
else if(dir=='D'){
if(w1[x+1][y]=='1'){
dir = 'R';
x = x+1;
y = y;
}
else if(w2[x+1][y]=='1'){
dir = 'D';
x = x+1;
y = y;
}
else if(w1[x+1][y-1]=='1'){
dir = 'L';
x = x+1;
y = y-1;
}
else {
dir = 'U';
x = x;
y = y;
}
}
printf("%c",dir);
if(x==1&&y==1)break;
}
printf("\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
const char d[4] = {'L', 'U', 'R', 'D'};
int main()
{
char ch;
bool G[6][6][4];
memset(G, 0, sizeof(G));
for (int i = 0; i < 9; i++) {
int d = i%2;
for (int j = 0; j < 4+d; j++) {
cin >> ch;
if (ch == '1') {
if (d % 2) {
G[i/2+1][j][2] = G[i/2+1][j+1][0] = 1;
} else {
G[i/2][j+1][3] = G[i/2+1][j+1][1] = 1;
}
}
}
}
int x = 1, y = 0, dir = 2;
string ans;
while(1){
if (!x && !y) break;
ans += d[dir];
int rh = (dir+1) % 4;
if (G[y][x][dir]) {
dir--;
dir = (dir == -1 ? 3 : dir);
} else if (!G[y+dy[dir]][x+dx[dir]][rh]) {
x += dx[dir], y += dy[dir];
if (!x && !y) break;
x += dx[rh], y += dy[rh];
dir = rh;
int nrh = (rh+1) % 4;
if (!G[y][x][nrh] && !(!x && !y)) {
x += dx[nrh], y += dy[nrh];
dir = nrh;
}
} else {
x += dx[dir]; y += dy[dir];
}
}
cout << ans << endl;
return 0;
} |
#include<string>
#include<vector>
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>
using namespace std;
#define REP(i,s,e) for(int i=int(s);i<=int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)
char lab[11][7];
string s;
void f(int i,int j){
if(i==1 && j==1) return;
else{
string a="URDLURDLUR";
int dx[]={0 ,-1,0,1, 0,-1,0};
int dy[]={-1, 0,0,0,-1, 0,0};
rep(k,4){
if(s[s.size()-1]==a[k]){
if(lab[i+dx[k]][j+dy[k]]-'0'==1){
s+=a[k+3];
if(dx[k]==0 && dy[k]==0) f(i,j+1); else f(i+2*dx[k],j+dy[k]);
}
else if(lab[i+dx[k+1]][j+dy[k+1]]-'0'==1){
s+=a[k+4];
if(dx[k+1]==0 && dy[k+1]==0) f(i,j+1); else f(i+2*dx[k+1],j+dy[k+1]);
}
else if(lab[i+dx[k+2]][j+dy[k+2]]-'0'==1){
s+=a[k+5];
if(dx[k+2]==0 && dy[k+2]==0) f(i,j+1); else f(i+2*dx[k+2],j+dy[k+2]);
}
else if(lab[i+dx[k+3]][j+dy[k+3]]-'0'==1){
s+=a[k+6];
if(dx[k+3]==0 && dy[k+3]==0) f(i,j+1); else f(i+2*dx[k+3],j+dy[k+3]);
}
break;
}
}
}
}
int main(){
REP(i,1,9){
if(i%2==1)
REP(j,1,4) cin >> lab[i][j];
else
REP(k,1,5) cin >> lab[i][k];
}
s+='R';
f(1,2);
cout << s << endl;
return 0;
} |
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
string in;
vector< string > wall_s, wall_v;
wall_s.push_back( "0000000000" );
for ( long long int i = 0; cin >> in; i++ ) {
if ( ( i % 2 ) == 0 ) {
wall_v.push_back( "0" + in + "0" );
}else {
wall_s.push_back( in );
}
if ( i == 8 ) break;
}
wall_s.push_back( "0000000000" );
long long int mx = 0;
long long int my = 0;
long long int d = 0;
while( true ) {
if ( d == 0 ) {
if ( wall_v[my][mx+1] == '1' ) {
cout << "R";
mx++;
if ( wall_s[my][mx] == '1' ) {
d = 3;
}
}else {
d = 1;
}
}else if ( d == 1 ) {
if ( wall_s[my+1][mx] == '1' ) {
cout << "D";
my++;
if ( wall_v[my][mx+1] == '1' ) {
d = 0;
}
}else {
d = 2;
}
}else if ( d == 2 ) {
if ( wall_v[my][mx] == '1' ) {
cout << "L";
mx--;
if ( wall_s[my+1][mx] == '1' ) {
d = 1;
}
}else {
d = 3;
}
}else {
if ( wall_s[my][mx] == '1' ) {
cout << "U";
my--;
if ( wall_v[my][mx] == '1' ) {
d = 2;
}
}else {
d = 0;
}
}
if ( mx == 0 && my == 0 && d == 0 ) break;
}
cout << endl;
return 0;
} |
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define INF INT_MAX / 3
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}
int a[35];
void solve()
{
string ans = "";
int pre, i, dir = 0, now = 0;
do
{
pre = (dir+2)%4;
for(i=(pre+1)%4;i!=pre;++i%=4)
{
if(a[now]>>i&1)
{
dir = i;
break;
}
}
if(i == pre) dir = pre;
switch(dir)
{
case 0:
ans += "R";
now += 1;
break;
case 1:
ans += "D";
now += 5;
break;
case 2:
ans += "L";
now -= 1;
break;
case 3:
ans += "U";
now -= 5;
break;
}
}
while(now != 0);
cout << ans << "\n";
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
fill_n(a,35,0);
string s;
REP(i,9)
{
cin >> s;
if(i%2==0)
{
int c = i/2;
REP(j,4) if(s[j]=='1')
{
a[c*5+j] += 1;
a[c*5+j+1] += 4;
}
}
else
{
int c = (i-1)/2;
REP(j,5) if(s[j]=='1')
{
a[c*5+j] += 2;
a[(c+1)*5+j] += 8;
}
}
}
solve();
return 0;
} |
#include<iostream>
#include<string>
using namespace std;
#define U 0
#define D 1
#define L 2
#define R 3
class point
{
public:
int x,y,d;
point()
{
x=y=0;
d=R;
}
void move()
{
if(d==R)
{
x++;
}
else if(d==L)
{
x--;
}
else if(d==U)
{
y--;
}
else
{
y++;
}
}
char dir()
{
if(d==U)
{
return 'U';
}
else if(d==D)
{
return 'D';
}
else if(d==L)
{
return 'L';
}
else
{
return 'R';
}
}
};
class map
{
public:
string s[9];
void input()
{
for(int i=0;i<9;i++)
{
cin>>s[i];
}
}
int state(int x, int y, int d)
{
if(d==U)
{
y=2*y-1;
}
else if(d==D)
{
y=2*y+1;
}
else if(d==L)
{
x=x-1;
y=y*2;
}
else
{
y=y*2;
}
if(y<0||y>=9||x<0||x>=s[y].length())
{
return 0;
}
else{
return s[y].at(x)-'0';
}
}
};
int main(void)
{
point p;
map m;
m.input();
int dir[4][4]=
{
{L,U,R,D},
{R,D,L,U},
{D,L,U,R},
{U,R,D,L}
};
while(!(p.d==L&&p.x==0&&p.y==0))
{
for(int i=0;i<4;i++)
{
if(p.d==i)
{
for(int j=0;j<4;j++)
{
if(m.state(p.x,p.y,dir[i][j])==1)
{
p.d=dir[i][j];
break;
}
}
break;
}
}
p.move();
cout<<p.dir();
}
cout<<endl;
} |
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
int zu[20][20];
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};//UP,RIGHT,DOWN,LEFT
char pr[]={'U','R','D','L'};
int main(){
for(int i=0;i<13;i++){
zu[0][i]=1;
zu[i][0]=1;
zu[12][i]=1;
zu[i][12]=1;
}
for(int i=0;i<9;i++){
if(i&1){
for(int j=0;j<5;j++){
char c;
cin>>c;
if(c-'0'){
zu[i+2][j*2+2]=1;
zu[i+1][j*2+2]=1;
zu[i+3][j*2+2]=1;
}
}
}else{
for(int j=0;j<4;j++){
char c;
cin>>c;
if(c-'0'){
zu[i+2][j*2+3]=1;
zu[i+2][j*2+2]=1;
zu[i+2][j*2+4]=1;
}
}
}
}
int x=2,y=2,d=1;
while(true){
int td=(d+3)%4;
for(int i=0;i<4;i++){
if(zu[y+dy[td]][x+dx[td]])break;
td=(td+1)%4;
}
d=td;
cout<<pr[d];
x+=2*dx[d];
y+=2*dy[d];
if(x==2 && y==2)break;
}
cout<<endl;
} |
#include<iostream>
using namespace std;
int main(){
int field[6][6]={0};
string s;
for(int i=0; i<5; i++){
cin >>s;
for(int j=0; j<s.size(); j++){
if(s[j] == '1'){
field[i][j+1]+=4;
field[i+1][j+1]+=1;
}
}
cin >>s;
if(i!=4){
for(int j=0; j<s.size(); j++){
if(s[j] == '1'){
field[i+1][j]+=2;
field[i+1][j+1]+=8;
}
}
}
}
int d = 2,x = 0,y = 1;
for(;;){
if(d == 1){
if(field[x][y]&2){
cout <<"U";
if(field[x][y]&1)d = 8;
else x--;
}
else{d = 2;y++;}
}
else if(d == 2){
if(field[x][y]&4){
cout <<"R";
if(field[x][y]&2) d = 1;
else y++;
}
else{d = 4;x++;}
}
else if(d == 4){
if(field[x][y]&8){
cout <<"D";
if(field[x][y]&4) d = 2;
else x++;
}
else{d = 8;y--;}
}
else if(d == 8){
if(field[x][y]&1){
cout <<"L";
if(field[x][y]&8) d = 4;
else y--;
}
else{d = 1;x--;}
}
if(x == 0 && y == 1) break;
}
cout <<endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
string side[4],Longitudinal[5];
int mox[2][2]={{1,-1},{0,-1}},moy[2][2]={{-1,1},{-1,0}};
char str[5]="URDL";
void serch(int x,int y,int then)
{
if(then==-1)then=3;
if(!x&&!y){
cout<<endl;
exit(0);
}
for(int i=0;i<4;i++){
int now=(then+i)%4,ka=now/2;
if(!(now%2)&&y+moy[0][ka]<5&&y+moy[0][ka]>-1&&side[y+moy[1][ka]][x]=='1'){
cout<<str[now];
serch(x,y+moy[0][ka],now-1);
}
else if(now%2&&x+mox[0][ka]<5&&x+mox[0][now/2]>-1&&Longitudinal[y][x+mox[1][ka]]=='1'){
cout<<str[now];
serch(x+mox[0][ka],y,now-1);
}
}
}
int main()
{
for(int i=0;i<4;i++)cin>>Longitudinal[i]>>side[i];
cin>>Longitudinal[4];
cout<<"R";
serch(1,0,0);
} |
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
std::fill((T*)ptr, (T*)ptr+size, value);
}
//参考http://hadrori.hateblo.jp/entry/aoj0037
const int dx[] ={-1,0,1,0};
const int dy[] ={0,-1,0,1};
int path[16][16][4];//0:L,1:U,2:R,3:D
int main()
{
char c;
for(int i = 0;i <9;i++){
if(i%2){
for(int j = 0;j < 5;j++){
cin >>c;
if(c =='1'){
path[i/2][j][3] = 1;
path[i/2+1][j][1] = 1;
}
}
}else{
for(int j = 0;j < 4;j++){
cin >>c;
if(c =='1'){
path[i/2][j][2] = 1;
path[i/2][j+1][0] = 1;
}
}
}
}
int x = 0,y = 0,d = 2;
/*
(前の方向:右 の場合)
進む方向の優先順位は、上、右、下、左となる。
(前の方向:左 の場合)
進む方向の優先順位は、下、左、上、右となる。
(前の方向:上 の場合)
進む方向の優先順位は、左、上、右、下となる。
(前の方向:下 の場合)
進む方向の優先順位は、右、下、左、上となる。*/
string dir ="LURD";
do{
for(int i = 0;i < 4;i++){
int dd =(d+i+3)%4;
if(path[y][x][dd]==1){
path[y][x][dd] -=1;
x +=dx[dd];
y +=dy[dd];
d = dd;
cout <<dir[dd];
break;
}
}
}while(x||y);
cout <<endl;
return 0;
} |
#include<iostream>
#include<cstdio>
#include<math.h>
#include<queue>
using namespace std;
int main(){
char stage[9][5] = {};
for (int i = 0; i < 9; i++){
cin >> stage[i];
for (int j = 0; j < 5; j++){
if (stage[i][j] != 0){
stage[i][j] -= '0';
}
}
}
//for (int i = 0; i < 9; i++){ for (int j = 0; j < 5; j++) printf("%d ", stage[i][j]); puts(""); }
int y = 0, x = 0, ny, nx, situ = 1;
int situ_y[4] = { -1, 0, 1, 0 }, situ_x[4] = { 0, 0, 0, -1 };
int np_y[4] = { -2, 0, 2, 0 }, np_x[4] = { 0, 1, 0, -1 };
char situ_char[4] = { 'U', 'R', 'D', 'L' };
do{
situ += 3;
situ %= 4;
//printf("%d,%d ", x, y);
for (int i = 0; i < 4; i++, situ = (situ + 1) % 4){
ny = y + situ_y[situ];
nx = x + situ_x[situ];
//printf(" %d:%d,%d", situ, ny, nx);
if (ny < 0 || 8 < ny || nx < 0 || 4 < nx) continue;
if (stage[ny][nx] == 1){
y += np_y[situ];
x += np_x[situ];
//printf("test\n");
printf("%c", situ_char[situ]);
break;
}
}
} while (y != 0 || x != 0);
puts("");
return 0;
} |
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
string wall_01[5];
string wall_02[4];
char wall_1(int x, int y){
if(x <= -1 || y <= -1 || x >= 4 || y >= 5){
return '0';
}
return wall_01[y][x];
}
char wall_2(int x, int y){
if(x <= -1 || y <= -1 || x >= 5 || y >= 4){
return '0';
}
return wall_02[y][x];
}
int main(){
for(int i = 0; i < 9; i++){
if(i % 2 == 0){
cin >> wall_01[i / 2];
}else{
cin >> wall_02[i / 2];
}
}
int pos_x = 0;
int pos_y = 0;
char dir_list[4] = {'R', 'D', 'L', 'U'};
char dir = 'R';
while(true){
//cout << pos_x << pos_y << dir << endl;
if(dir == 'R'){
if(wall_2(pos_x, pos_y - 1) == '1'){
cout << "U";
pos_y--;
dir = 'U';
}else if(wall_1(pos_x, pos_y) == '1'){
cout << "R";
pos_x++;
}else if(wall_2(pos_x, pos_y) == '1'){
dir = 'D';
}else{
dir = 'L';
}
}else if(dir == 'D'){
if(wall_1(pos_x, pos_y) == '1'){
cout << "R";
pos_x++;
dir = 'R';
}else if(wall_2(pos_x, pos_y) == '1'){
cout << "D";
pos_y++;
}else if(wall_1(pos_x - 1, pos_y) == '1'){
dir = 'L';
}else{
dir = 'U';
}
}else if(dir == 'L'){
if(wall_2(pos_x, pos_y) == '1'){
cout << "D";
pos_y++;
dir = 'D';
}else if(wall_1(pos_x - 1, pos_y) == '1'){
cout << "L";
pos_x--;
}else if(wall_2(pos_x, pos_y - 1) == '1'){
dir = 'U';
}else{
dir = 'R';
}
}else if(dir == 'U'){
if(wall_1(pos_x - 1, pos_y) == '1'){
cout << "L";
pos_x--;
dir = 'L';
}else if(wall_2(pos_x, pos_y - 1) == '1'){
cout << "U";
pos_y--;
}else if(wall_1(pos_x, pos_y) == '1'){
dir = 'R';
}else{
dir = 'D';
}
}
if(pos_x == 0 && pos_y == 0){
cout << endl;
break;
}
}
return 0;
} |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
struct point
{
bool b[4];
};
int main()
{
point a[5][5];
for (int i = 0; i < 5; i++)
{
for (int l = 0; l < 5; l++)
{
for (int k = 0; k < 4; k++)
{
a[i][l].b[k] = false;
}
}
}
for (int i = 0; i < 5; i++)
{
string str;
cin >> str;
for (int l = 0; l < 4; l++)
{
a[i][l].b[1] = a[i][l + 1].b[3] = str[l] - '0';
}
if (i != 5 - 1)
{
cin >> str;
for (int l = 0; l < 5; l++)
{
a[i][l].b[2] = a[i + 1][l].b[0] = str[l] - '0';
}
}
}
int x, y, v;
x = y = 0;
v = 1;
while (1)
{
int d[4] = { -1 + 4,0 + 4,+1 + 4,+2 + 4 };
int dx[4] = { 0,1,0,-1 };
int dy[4] = { -1,0,1,0 };
char dc[5] = "URDL";
for (int i = 0; i < 4; i++)
{
int di = (v + d[i]) % 4;
if (a[y][x].b[di])
{
x += dx[di];
y += dy[di];
v = di;
cout << dc[di];
break;
}
}
if (x == y&&x == 0)
{
cout << endl;
return 0;
}
}
} |
#include <bits/stdc++.h>
using namespace std;
const int vx[]={1,0,-1,0};
const int vy[]={0,-1,0,1};
const char vec[]={'R','U','L','D'};
int main(void){
string s;
int cd=0;
int cm[2]={0,1};
vector<vector<vector<bool> > >m(5,vector<vector<bool> >(5,vector<bool>(4,false)));
for (int i = 0; i < 9; ++i) {
cin >> s;
for (int j = 0; j < s.length(); ++j) {
if (i % 2 == 0) {
if (s[j] == '1') {
m[i / 2][j][0] = true;
m[i / 2][j + 1][2] = true;
}
} else {
if (s[j] == '1') {
m[(i - 1) / 2][j][3] = true;
m[(i + 1) / 2][j][1] = true;
}
}
}
}
int nd[4];
int d;
cout<<"R";
while(cm[0]!=0||cm[1]!=0){
for (int i = 0; i < 4; ++i) {
d=(cd+1-i>3)?0:cd+1-i;
if(d<0)d+=4;
nd[i]=d;
}
for (int i = 0; i < 4; ++i) {
if(m[cm[0]][cm[1]][nd[i]]){
cm[0]+=vy[nd[i]];
cm[1]+=vx[nd[i]];
cd=nd[i];
cout<<vec[nd[i]];
break;
}
}
}
cout<<endl;
return 0;
}
|
#include<stdio.h>
char f[6][6],s[6],i,j,a,y,x,p,b;
int main()
{
for(;i<9;++i,b=!b){
scanf("%s",s);
for(j=0;j<4+b;++j){
a=s[j]-48;
f[i/2][j]|=a<<1+b;
f[i/2+b][j+!b]|=a<<3-b*3;
}
}
do{
while(!((f[y][x]>>(p=(p+1)%4))&1));
putchar("URDL"[p]);
x+=p?2-p:0;
y+=p==3?0:p-1;
p=(p+2)%4;
}while(y|x|f[0][0]==6&p==3);
return!puts("");
} |
#include<bits/stdc++.h>
using namespace std;
string side[4],Longitudinal[5];
void righ(int x,int y);
void lef(int x,int y);
void up(int x,int y);
void down(int x,int y);
void serch(int x,int y,int then);
int main()
{
for(int i=0;i<4;i++)cin>>Longitudinal[i]>>side[i];
cin>>Longitudinal[4];
cout<<"R";
serch(1,0,0);
}
void righ(int x,int y)
{
if(x+1<5&&Longitudinal[y][x]=='1'){
cout<<"R";
serch(x+1,y,0);
}
}
void lef(int x,int y)
{
if(x-1>-1){
if(Longitudinal[y][x-1]=='1'){
cout<<"L";
serch(x-1,y,2);
}
}
}
void up(int x,int y)
{
if(y-1>-1){
if(side[y-1][x]=='1'){
cout<<"U";
serch(x,y-1,3);
}
}
}
void down(int x,int y)
{
if(y+1<5&&side[y][x]=='1'){
cout<<"D";
serch(x,y+1,1);
}
}
void serch(int x,int y,int then)
{
if(x==0&&y==0){
cout<<endl;
exit(0);
}
if(then==0){
up(x,y);
righ(x,y);
down(x,y);
lef(x,y);
}
else if(then==1){
righ(x,y);
down(x,y);
lef(x,y);
up(x,y);
}
else if(then==2){
down(x,y);
lef(x,y);
up(x,y);
righ(x,y);
}
else{
lef(x,y);
up(x,y);
righ(x,y);
down(x,y);
}
} |
#include<stdio.h>
char w[5][5];
char b[128], *p;
char i,j;
void F(int v){
scanf("%s",b);
for(p=b; *p; p++){
w[p-b+1-v][j+v]|=((w[p-b][j]|=(*p==49)<<3-v)&8>>v)>>2;
}
j+=v;
}
int main(){
for (;F(0),j-4;F(1));
for(i=j=(*b=3)^3;i+="BABC"[*b]-66,j+="ABCB"[*b]-66,putchar("ULDR"[*b]),i+j;)
for((*b+=1)&=~4;!(w[i][j]&(1<<*b)); (*b+=3)&=~4);
return !puts("");
}
|
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
int main() {
vector<string> s;
string t;
while(cin >> t) s.pb(t);
int d[s.size()+2][s[1].size()*2+1];
memset(d,0,sizeof(d));
rep(i,s.size()) {
rep(j,s[i].size()) {
if(i%2) {
d[i+1][j*2+1]=(s[i][j]=='1');
} else {
d[i+1][j*2+2]=(s[i][j]=='1');
}
}
}
string ans="";
int x=1,y=1,z=0;
char c[4]={'U','R','D','L'};
for(int i=0; i<4; i++) {
int k=(z+3)%4;
int nx=x+dx[(i+k)%4],ny=y+dy[(i+k)%4];
if(d[nx][ny]==1) {
x+=dx[(i+k)%4]*2;
y+=dy[(i+k)%4]*2;
ans+=c[(i+k)%4];
z=(i+k)%4;
break;
}
}
while(x!=1 || y!=1) {
for(int i=0; i<4; i++) {
int k=(z+3)%4;
int nx=x+dx[(i+k)%4],ny=y+dy[(i+k)%4];
if(d[nx][ny]==1) {
x+=dx[(i+k)%4]*2;
y+=dy[(i+k)%4]*2;
ans+=c[(i+k)%4];
z=(i+k)%4;
break;
}
}
}
pr(ans);
return 0;
}
|
#include<iostream>
#include<string>
using namespace std;
struct man{int x,y,d;};
int main(){
string st[9];
int i,j,k;
for(i=0;i<9;i++) cin >> st[i];
bool f=false,mo=false;
man m;
m.x=1;m.y=0;m.d=0;
int c=0;
cout << "R";
while(1){
c++;
mo=false;
if(m.x==1&&m.y==1&&m.d==2) {
//cout << "L";
break;
}
if(m.x==0&&m.y==1&&f) {
//cout << "U";
break;
}
f=true;
//cout << m.x<<":"<<m.y<<":"<<m.d << endl;
if(m.d==0){
if(m.y>0){
if(st[m.y*2-1][m.x]=='1') {
cout << "U";
m.d=3;
continue;
}
}
if(m.y<5){
if(st[m.y*2][m.x]=='1') {
m.x++;
cout << "R";
continue;
}
}
if(m.y<4){
if(st[m.y*2+1][m.x]=='1') {
m.x++;
m.y++;
cout << "D";
m.d=1;
continue;
}
}
m.y++;
cout << "L";
m.d=2;
continue;
}
if(m.d==1){
if(m.y<5){
if(st[m.y*2][m.x-1]=='1') {
cout <<"R";
m.d=0;
continue;
}
}
if(m.x>0&&m.y<4){
if(st[m.y*2+1][m.x-1]=='1') {
m.y++;
cout << "D" ;
mo=true;
continue;
}
}
if(m.x>1&&m.y<5){
if(st[m.y*2][m.x-2]=='1') {
m.x--;
m.y++;
cout << "L";
m.d=2;
continue;
}
}
m.x--;
cout << "U";
m.d=3;
continue;
}
if(m.d==2){
if(m.x>0){
if(st[m.y*2-1][m.x-1]=='1') {
cout << "D";
m.d=1;
continue;
}
}
if(m.x>1&&m.y>0){
if(st[(m.y-1)*2][m.x-2]=='1') {
m.x--;
cout << "L" ;
mo=true;
continue;
}
}
if(m.x>0&&m.y>1){
if(st[(m.y-1)*2-1][m.x-1]=='1') {
m.x--;
m.y--;
cout << "U";
m.d=3;
continue;
}
}
m.y--;
cout << "R";
m.d=0;
continue;
}
if(m.d==3){
if(m.y>0){
if(st[(m.y-1)*2][m.x-1]=='1') {
cout << "L";
m.d=2;
continue;
}
}
if(m.y>1){
if(st[(m.y-1)*2-1][m.x]=='1') {
m.y--;
cout << "U" ;
mo=true;
continue;
}
}
if(m.y>0){
if(st[(m.y-1)*2][m.x]=='1') {
m.x++;
m.y--;
cout << "R";
m.d=0;
continue;
}
}
m.x++;
cout << "D";
m.d=1;
continue;
}
//if(!mo)m.d=(m.d+2)%4;
}
cout << endl;
return 0;
} |
#include <stdio.h>
char w[9][6];
bool is_up(int x, int y){
if(y <= 0){ return false; }
return w[y*2-1][x] == '1';
}
bool is_down(int x, int y){
if(y >= 4){ return false; }
return w[y*2+1][x] == '1';
}
bool is_left(int x, int y){
if(x <= 0){ return false; }
return w[y*2][x-1] == '1';
}
bool is_right(int x, int y){
if(x >= 4){ return false; }
return w[y*2][x] == '1';
}
int main(void){
char r[100];
int st = 0;
int px=0, py=0;
for(int i=0;i<9;++i){
scanf("%s", w+i);
}
r[st++] = 'R';
px=1;
while(px!=0 || py!=0){
switch(r[st-1]){
case 'U':
if(is_left(px, py)){ r[st++] = 'L'; px--; }
else if(is_up(px, py)){ r[st++] = 'U'; py--; }
else if(is_right(px, py)){ r[st++] = 'R'; px++; }
else{ r[st++] = 'D'; py++; }
break;
case 'R':
if(is_up(px, py)){ r[st++] = 'U'; py--; }
else if(is_right(px, py)){ r[st++] = 'R'; px++; }
else if(is_down(px, py)){ r[st++] = 'D'; py++; }
else{ r[st++] = 'L'; px--; }
break;
case 'D':
if(is_right(px, py)){ r[st++] = 'R'; px++; }
else if(is_down(px, py)){ r[st++] = 'D'; py++; }
else if(is_left(px, py)){ r[st++] = 'L'; px--; }
else{ r[st++] = 'U'; py--; }
break;
case 'L':
if(is_down(px, py)){ r[st++] = 'D'; py++; }
else if(is_left(px, py)){ r[st++] = 'L'; px--; }
else if(is_up(px, py)){ r[st++] = 'U'; py--; }
else{ r[st++] = 'R'; px++; }
break;
default:
puts("error");
break;
}
//printf("%d,%d\n",px,py);
}
r[st] = '\0';
puts(r);
//getchar();getchar();
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.