usaco-palsquare-pass

这个居然还一下就通过了,呵呵:

/*
ID: qq104801
LANG: C++
TASK: palsquare
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

/* for debug only:counter
*/
void debug_dummy(void)
{
    return;
}

int base;
char x[64];
char num[]={‘0‘,‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘,
            ‘A‘,‘B‘,‘C‘,‘D‘,‘E‘,‘F‘,‘G‘,‘H‘,‘I‘,‘J‘};

void xnum(int a,int b)
{
    int i=0;
    int c=a;
    while(c!=0)
    {
        x[i]=num[c%b];
        c=c/b;
        i++;
    }
    x[i]=‘\0‘;
    //printf("%s  len:%d\n",x,strlen(x));
}

int ispalindromes(char* s)
{
    int l=strlen(s);
    int f=1;
    for(int i=0;i<(l/2);i++)
    {
        if(s[i]!=s[l-i-1])
        {
            f=0;
            break;
        }
    }
    return f;
}

void test(FILE* f)
{
    int bb;
    for(int i=1;i<301;i++)
    {
        bb=i*i;
        xnum(bb,base);
        if (ispalindromes(x))
            fprintf(f,"%d %d\n",i,bb);
    }
}

main () {
    FILE *fin = fopen ("palsquare.in", "r");
    FILE *fout = fopen ("palsquare.out", "w");
    fscanf(fin,"%d",&base);
    //printf("%d\n",base);
    test(fout);
    fclose(fin);
    fclose(fout);
    exit (0);
}

测试用例:

USER: ll tom [qq104801]
TASK: namenum
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.005 secs, 3556 KB]
   Test 2: TEST OK [0.005 secs, 3556 KB]
   Test 3: TEST OK [0.005 secs, 3556 KB]
   Test 4: TEST OK [0.014 secs, 3556 KB]
   Test 5: TEST OK [0.011 secs, 3556 KB]
   Test 6: TEST OK [0.011 secs, 3556 KB]
   Test 7: TEST OK [0.008 secs, 3556 KB]
   Test 8: TEST OK [0.008 secs, 3556 KB]
   Test 9: TEST OK [0.011 secs, 3556 KB]
   Test 10: TEST OK [0.008 secs, 3556 KB]
   Test 11: TEST OK [0.019 secs, 3556 KB]
   Test 12: TEST OK [0.016 secs, 3556 KB]
   Test 13: TEST OK [0.008 secs, 3556 KB]
   Test 14: TEST OK [0.008 secs, 3556 KB]
   Test 15: TEST OK [0.014 secs, 3556 KB]

All tests OK.

Your program (‘namenum‘) produced all correct answers! This is your submission #7 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 ----
4734
------- test 2 ----
234643
------- test 3 ----
5747867437
------- test 4 ----
223
------- test 5 ----
532
------- test 6 ----
546
------- test 7 ----
53662
------- test 8 ----
5455426
------- test 9 ----
26678268463
------- test 10 ----
463373633623
------- test 11 ----
282742662
------- test 12 ----
463373633623
------- test 13 ----
2336
------- test 14 ----
5264
------- test 15 ----
426

Keep up the good work!
Thanks for your submission!

说明理解了题意。

时间: 2024-11-08 11:38:40

usaco-palsquare-pass的相关文章

Usaco Open09 Gold

Problem 1: Ski Lessons [Brian Jacokes, 2002] Farmer John wants to take Bessie skiing in Colorado. Sadly, Bessie is not really a very good skier. Bessie has learned that the ski resort is offering S (0 <= S <= 100) ski classes throughout the day. Les

COGS 696. [IOI1996][USACO 2.3] 最长前缀

★   输入文件:prefix.in   输出文件:prefix.out   简单对比时间限制:1 s   内存限制:128 MB 描述 USACO 2.3.1 IOI96 在生物学中,一些生物的结构是用包含其要素的大写字母序列来表示的.生物学家对于把长的序列分解成较短的序列(即元素)很感兴趣. 如果一个集合 P 中的元素可以通过串联(元素可以重复使用,相当于 Pascal 中的 “+” 运算符)组成一个序列 S ,那么我们认为序列 S 可以分解为 P 中的元素.元素不一定要全部出现(如下例中B

USACO 1.2 Palindromic Squares

Palindromic SquaresRob Kolstad Palindromes are numbers that read the same forwards as backwards. The number 12321 is a typical palindrome. Given a number base B (2 <= B <= 20 base 10), print all the integers N (1 <= N <= 300 base 10) such that

USACO prefix TrieTree + DP

/* ID:kevin_s1 PROG:prefix LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdlib>

【USACO 1.3.4】牛式

[題目描述 ] 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ---------- * * * * * * ---------- * * * * 数字只能取代*,当然第一位不能为0,况且给定的数字里不包括0. 注意一下在美国的学校中教的"部分乘积",第一部分乘积是第二个数的个位和第一个数的积,第二部分乘积是第二个数的十位和第一个数的乘积. 写一个程序找出所有的牛式. [格式] INPUT FORMAT: (f

USACO Chapter 1 Section 1.1

USACO的题解和翻译已经很多了... 我只是把自己刷的代码保存一下. 1.PROB Your Ride Is Here 1 /* 2 ID:xiekeyi1 3 PROG:ride 4 LANG:C++ 5 */ 6 7 #include<bits/stdc++.h> 8 using namespace std ; 9 10 int main() 11 { 12 freopen("ride.in","r",stdin); 13 freopen(&quo

pass语句

Python pass是空语句,是为了保持程序结构的完整性.  pass 不做任何事情,一般用做占位语句. #!/usr/bin/python # -*- coding: UTF-8 -*- # 输出 Python 的每个字母 for letter in 'Python': if letter == 'h': pass print '这是 pass 块' print '当前字母 :', letter print "Good bye!" 执行结果: 当前字母 : P 当前字母 : y 当

USACO Your Ride Is Here

[USACO]Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect loyal supporters from here on Earth. Unfortunately, they only have room to pick up one group of followers on each trip. They do,

usaco月赛,2017.1总结

T1:跳舞的奶牛 大致题意:一个体积为k的舞台能够同时容纳k只奶牛一起跳舞,他们每头奶牛的跳舞时间不同,如果有一只奶牛跳完了第k+1头奶牛就会立刻上场跳舞,当所有奶牛跳完舞以后我们认为这次表演结束.现在给出奶牛个数,最多用时,每头奶牛的跳舞时间.求舞台最小为多大. 思路:本来写了个程序以为这道题很简单,刚开始排一下序然后就行了,结果交了以后发现只过了五组,然后才发现这道题不能改变顺序(所以说为什么我改变顺序了还是能过五组,usaco的数据也好水......),所以说我想到了堆,然后就用堆写了一下

插入排序的优化【不靠谱地讲可以优化到O(nlogn)】 USACO 丑数

首先我们先介绍一下普通的插排,就是我们现在一般写的那种,效率是O(n^2)的. 普通的插排基于的思想就是找位置,然后插入进去,其他在它后面的元素全部后移,下面是普通插排的代码: 1 #include<iostream> 2 #include<fstream> 3 #include<stdio.h> 4 using namespace std; 5 int a[200000]; 6 int p[200000]; 7 8 int main(){ 9 ios::sync_wi