Skip to content

Instantly share code, notes, and snippets.

@orisano
Created November 11, 2012 15:38
Show Gist options
  • Save orisano/4055247 to your computer and use it in GitHub Desktop.
Save orisano/4055247 to your computer and use it in GitHub Desktop.
PCK本戦:後になって書いてみた編
#include <stdio.h>
enum {A, X, Y, Z, W, B, ERROR};
int map[6][2] = {
{X, Y},
{ERROR, Z},
{X, ERROR},
{W, B},
{B, Y},
{Y, X}
};
int main(void)
{
int sw;
int now_pos;
for (now_pos = A; (sw = getchar()) != '#';){
if (sw == '\n'){
puts(now_pos == B ? "Yes" : "No");
now_pos = A;
continue;
}
if (now_pos == ERROR) continue;
now_pos = map[now_pos][sw == '1'];
}
return (0);
}
#include <stdio.h>
#define LIMIT (10000)
int main(void)
{
int n;
int mem[2][10000];
int ct;
int under_line;
int dl;
int i, j;
int index;
while (scanf("%d", &n), n){
for (i = 0; i < n; i++){
scanf("%d", &mem[0][i]);
}
under_line = n;
for (ct = 0; ct < LIMIT; ct++){
for (i = 0; i < under_line && mem[ct & 1][i] == i + 1; i++);
if (i == under_line) break;
dl = index = 0;
for (i = 0; i < under_line; i++){
dl -= !(--mem[ct & 1][i]);
if (mem[ct & 1][i]) mem[!(ct & 1)][index++] = mem[ct & 1][i];
}
mem[!(ct & 1)][index] = under_line;
under_line = under_line + 1 + dl;
}
printf("%d\n", ct != LIMIT ? ct : -1);
}
return (0);
}
#include <stdio.h>
double mpow(double x, int n);
int ch2dec(char hex);
void bit_conv(char *bit, int num);
int main(void)
{
char bit[64];
char format[16];
double frac;
int dec;
int n;
int i;
int max;
scanf("%d", &n);
while (n--){
getchar();
for (i = 0; i < 8; i++){
bit_conv(bit + (i * 4), ch2dec(getchar()));
}
if (*bit) printf("-");
dec = 0;
for (i = 0; i < 24; i++){
dec = (dec << 1) + bit[1 + i];
}
frac = max = 0;
for (i = 0; i < 7; i++){
if (bit[25 + i]){
frac += mpow(0.5, i + 1);
max = i;
}
}
sprintf(format, "%s.%d%s\n", "%", max + 1, "lf");
printf(format, frac + dec);
}
return (0);
}
void bit_conv(char *bit, int num)
{
int i;
int index;
for (index = 0, i = 3; i >= 0; i--, index++){
bit[index] = (num >> i) & 1;
}
return;
}
int ch2dec(char hex){
if ('0' <= hex && hex <= '9') return (hex - '0');
return ((hex - 'a') + 10);
}
double mpow(double x, int n)
{
int i;
double ret;
ret = 1;
for (i = 0; i < n; i++){
ret *= x;
}
return (ret);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment