CSU 1785: 又一道简单题
1785: 又一道简单题
Submit Page Summary Time Limit: 5 Sec Memory Limit: 128 Mb Submitted: 602 Solved: 234
Description
输入一个四个数字组成的整数 n,你的任务是数一数有多少种方法,恰好修改一个数字,把它 变成一个完全平方数(不能把首位修改成 0)。比如 n=7844,有两种方法:3844=62^2和 7744=88^2。
Input
输入第一行为整数 T (1<=T<=1000),即测试数据的组数,以后每行包含一个整数 n (1000<=n<=9999)。
Output
对于每组数据,输出恰好修改一个数字,把 n 变成完全平方数的方案数。
Sample Input
2
7844
9121
Sample Output
Case 1: 2
Case 2: 0
Hint
Source
湖南省第十一届大学生计算机程序设计竞赛
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<set>
#include<map>
#include<sstream>
#include<queue>
#include<cmath>
#include<list>
#include<vector>
#include<string>
using namespace std;
#define long long ll
const double PI = acos(-1.0);
const double eps = 1e-;
const int inf = 0x3f3f3f3f;
const int N = ;
int n, m, tot;
int a[];
int r[], c[];
int x, y, pr, pc, k = ;
int ok(int x)
{
int tp=sqrt(x*1.0);
return tp*tp==x;
}
int change(string s)
{
int sum = ;
for(int i=; i<s.size(); i++)
{
sum = sum * + s[i] - '';
}
return sum;
}
int sq[];
void init()
{
int k = ;
for(int i=; i<; i++)
sq[k++] = i * i;
}
int main()
{ int t, k = ;
cin >> t;
while(t--)
{
string s, s1, s2, s3, s4;
int cnt = ;
cin>>s;
int a,b,c,d;
s1 = s;s2 = s;s3 = s;s4 = s; //将s分别复制给中间变量
a = s1[]-''; b = s2[]-''; c = s3[]-''; d = s4[]-''; //记录原4位数各个数位数值
//printf("%d %d %d %d\n",a,b,c,d);
for(int i=; i<= ; i++) //第一位改变不能和原来的相等&&第一位不能为0
{
if(i==a) continue; //注意!不能把i!=a写在for循环里面 一遇到a会直接跳出循环而漏掉情况!!!
s1[] = i + ''; //改变第一位
//cout<<s1[0]<<endl;
if(ok(change(s1))) { //将字符串变为数值再判断是否为完全平方数
//printf("%d\n",change(s1));
cnt++;
}
}
for(int i=; i<= ; i++)
{
if(i==b) continue;
s2[] = i + '';
//cout<<s2[1] <<endl;
if(ok(change(s2))){
//printf("%d\n",change(s2));
cnt++;
}
}
for(int i=; i<= ; i++)
{
if(i==c) continue;
s3[] = i + '';
//cout<<s3[2]<<endl;
if(ok(change(s3))) {
//printf("%d\n",change(s3));
cnt++;
}
}
for(int i=; i<= ; i++)
{
if(i==d) continue;
s4[] = i + '';
//cout<<s4[3]<<endl;
if(ok(change(s4))) {
//printf("%d\n",change(s4));
cnt++;
}
}
printf("Case %d: ",k++);
cout<<cnt<<endl;
}
return ;
}
CSU 1785: 又一道简单题的更多相关文章
- 又一道简单题&&Ladygod(两道思维水题)
Ladygod Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit S ...
- 中南大学2018年ACM暑期集训前期训练题集(入门题) X: 又一道简单题
简直智障,上一题V题,样例输出里面的“Case:”不要输出,到了这题又是要输出的了 #include<iostream> using namespace std; int num[1000 ...
- P3928 SAC E#1 - 一道简单题 Sequence2
题目背景 小强和阿米巴是好朋友. 题目描述 小强喜欢数列.有一天,他心血来潮,写下了三个长度均为n的数列. 阿米巴也很喜欢数列.但是他只喜欢其中一种,波动数列. 阿米巴把他的喜好告诉了小强.小强便打算 ...
- UVa 11991 一道简单题
https://vjudge.net/problem/UVA-11991 题意:给出一个包含n个整数的数组,你需要回答若干询问.每次询问两个整数k和v,输出从左到右第k个v的下标. 思路: 把每个数字 ...
- 【Luogu】 P3928 SAC E#1 - 一道简单题 Sequence2
[题目]洛谷10月月赛R1 提高组 [算法]递推DP+树状数组 [题解]列出DP递推方程,然后用树状数组维护前后缀和. #include<cstdio> #include<cstri ...
- 洛谷P3928 SAC E#1 - 一道简单题 Sequence2
提交地址 题目背景 小强和阿米巴是好朋友. 题目描述 小强喜欢数列.有一天,他心血来潮,写下了三个长度均为n的数列. 阿米巴也很喜欢数列.但是他只喜欢其中一种,波动数列. 阿米巴把他的喜好告诉了小强. ...
- Go: LeetCode简单题,简单做(sort.Search)
前言 正值端午佳节,LeetCode也很懂.这两天都是简单题,早点做完去包粽子. 故事从一道简单题说起 第一个错误的版本 简单题 你是产品经理,目前正在带领一个团队开发新的产品.不幸的是,你的产品的最 ...
- QDUOJ 一道简单的数据结构题 栈的使用(括号配对)
一道简单的数据结构题 发布时间: 2017年6月3日 18:46 最后更新: 2017年6月3日 18:51 时间限制: 1000ms 内存限制: 128M 描述 如果插入“+”和“1”到 ...
- 面试一个百度T7程序员,一道简单的题没答上来!网友却都在吐槽面试官!
程序员面试时都考些什么? 一个面试官得意洋洋地说自己面了一个百度T7,出了一道coding题,结果对方连最长上升子序列都写不出来. 楼主本想嘲弄一下百度T7的代码水平低,没想到网友们炸开了锅,纷纷 ...
随机推荐
- 动态规划:HDU1087-Super Jumping! Jumping! Jumping!(最大上升子序列和)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- BZOJ 1531: [POI2005]Bank notes
按余数分类 单调队列优化 #include<cstdio> using namespace std; int n,m,b[205],c[205],F[20005]; struct node ...
- 【Two Sum】cpp
题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...
- leetcode 【 Merge Sorted Array 】python 实现
题目: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note:You may assume ...
- Appium的三种等待时间设置方法
#三种appium设置等待时间的方法 #作者:Mr.Dantes #参考了网上的资料,然后进行了梳理 #第一种 sleep(): 设置固定休眠时间. python 的 time 包提供了休眠方法 ...
- 【数据结构与算法】Fibonacci Sequence
学计算机的对 Fibonacci 都并不陌生,在课堂上一讲到递归几乎都会提到 Fibonacci 数列.不久前,我对 Fibonacci 产生了一些兴趣,就在这里把自己的想法给记录下来. 递推公式: ...
- Struts2请求流程
1. 一个请求在Struts2框架中的处理步骤: a) 客户端初始化一个指向Servlet容器的请求: b) 根据Web.xml配置,请求首先经过ActionContextCleanUp过滤器,其为可 ...
- Excel的数据批量替换
该篇文章照抄自:http://www.cnblogs.com/xwgli/p/5845317.html 在 Excel 中使用正则表达式进行查找与替换 在 Excel 中,使用 Alt+F11 快捷 ...
- icheck 动态设置选中,判断是否选择
$(this).iCheck('check'); //启用禁用上级编号 $('#OnPar').on('ifUnchecked', function (event) { ...
- jQuery操作DOM基础 - 元素属性的查看与设置
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...