日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CSU 1785: 又一道简单题

發布時間:2023/12/20 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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-6; const int inf = 0x3f3f3f3f; const int N = 100005; int n, m, tot; int a[10550]; int r[550], c[550]; int x, y, pr, pc, k = 1; int ok(int x) {int tp=sqrt(x*1.0);return tp*tp==x; } int change(string s) {int sum = 0;for(int i=0; i<s.size(); i++){sum = sum * 10 + s[i] - '0';}return sum; } int sq[100005]; void init() {int k = 0;for(int i=32; i<100; i++)sq[k++] = i * i; } int main() {int t, k = 1;cin >> t;while(t--){string s, s1, s2, s3, s4;int cnt = 0;cin>>s;int a,b,c,d;s1 = s;s2 = s;s3 = s;s4 = s; //將s分別復制給中間變量a = s1[0]-'0'; b = s2[1]-'0'; c = s3[2]-'0'; d = s4[3]-'0'; //記錄原4位數各個數位數值//printf("%d %d %d %d\n",a,b,c,d);for(int i=1; i<=9 ; i++) //第一位改變不能和原來的相等&&第一位不能為0 {if(i==a) continue; //注意!不能把i!=a寫在for循環里面 一遇到a會直接跳出循環而漏掉情況!!!s1[0] = i + '0'; //改變第一位//cout<<s1[0]<<endl;if(ok(change(s1))) { //將字符串變為數值再判斷是否為完全平方數//printf("%d\n",change(s1));cnt++;}}for(int i=0; i<=9 ; i++){if(i==b) continue;s2[1] = i + '0';//cout<<s2[1] <<endl;if(ok(change(s2))){//printf("%d\n",change(s2));cnt++;}}for(int i=0; i<=9 ; i++){if(i==c) continue;s3[2] = i + '0';//cout<<s3[2]<<endl;if(ok(change(s3))) {//printf("%d\n",change(s3));cnt++;}}for(int i=0; i<=9 ; i++){if(i==d) continue;s4[3] = i + '0';//cout<<s4[3]<<endl;if(ok(change(s4))) {//printf("%d\n",change(s4));cnt++;}}printf("Case %d: ",k++);cout<<cnt<<endl;}return 0; } View Code

?

轉載于:https://www.cnblogs.com/Roni-i/p/8711644.html

總結

以上是生活随笔為你收集整理的CSU 1785: 又一道简单题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。