【51nod - 1087】 1 10 100 1000(找规律推公式,水,map)
生活随笔
收集整理的這篇文章主要介紹了
【51nod - 1087】 1 10 100 1000(找规律推公式,水,map)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題干:
1,10,100,1000...組成序列1101001000...,求這個序列的第N位是0還是1。
Input
第1行:一個數T,表示后面用作輸入測試的數的數量。(1 <= T <= 10000)?
第2 - T + 1行:每行1個數N。(1 <= N <= 10^9)
Output
共T行,如果該位是0,輸出0,如果該位是1,輸出1。
Sample Input
3 1 2 3Sample Output
1 1 0解題報告:
? ? 用了map,剛開始直接沖一下50W的數組發現1e8多,然后開了70W發現成了1e7.。。于是發現可能是開大了然后試了試5W發現就1e9多了。
AC代碼:
#include<bits/stdc++.h>using namespace std; int a[50000 + 5]; map<int , int> mp; int main() {int top = -1;a[0] = 1;mp[a[0] ] = 1; for(int i = 1 ;i<=50000 && a[i]<=(int)1e9; i++) {a[i] = a[i-1]+i;mp[a[i] ] =1;}int t,n; // cout<<a[50000];cin>>t;while(t--) {scanf("%d",&n);printf("%d\n",mp[n]);} return 0 ;}這題數據出水了啊,不用map也能過?因為最大數據是1e8.。。看代碼:
#include<bits/stdc++.h>using namespace std; int a[50000 + 5]; map<int , int> mp; int main() {int top = -1;a[0] = 1;mp[a[0] ] = 1; for(int i = 1 ;i<=50000 && a[i]<=(int)1e9; i++) {a[i] = a[i-1]+i;mp[a[i] ] =1;}int t,n; // cout<<a[50000];cin>>t;while(t--) {scanf("%d",&n);if(n > 100001010) printf("hahaha\n");printf("%d\n",mp[n]);} return 0 ;}?
總結
以上是生活随笔為你收集整理的【51nod - 1087】 1 10 100 1000(找规律推公式,水,map)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2017各大银行信用卡排名 热门银行信用
- 下一篇: 【HDU - 2112】 HDU Tod