社区讨论
24tps求助!!
P10246 Exciting Days参与者 1已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @m58ybelt
- 此快照首次捕获于
- 2024/12/29 09:48 去年
- 此快照最后确认于
- 2024/12/29 09:58 去年
CPP
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 4e5+100;
ll a[maxn];
int p;
struct node{
ll month, day;
bool operator<(const node &o){
if(month != o.month) return month < o.month;
else return day < o.day;
}
}b[maxn];
int bzz;
ll quick_pow(int a, int b){
ll ans = 1;
while(b){
if((b&1) == 1) ans *= a;
a *= a;
b >>= 1;
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
ll T; cin >> T;
while(T--){
ll n, k, max_n = 0;
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> a[i];
ll t = a[i], len = 0;
while(t){
len++;
t /= 10;
}
max_n = max(max_n, n*quick_pow(10,len)+a[i]);
}
if(k == 1){
cout << 0 << "\n";
continue;
}
for(ll p = k; p <= max_n; p*=k){//忽略k=1,不开longlong
ll i = 10;
while(p/i > n) {i *= 10;}
for(; p/i >= 1; i*=10){
ll month = p/i, day = p%i;
ll tday = day;
ll tlen = 1;
while(tday){
tlen *= 10;
tday /= 10;
}
if(month*tlen + day != p) continue;//1 024 要跳过
//cout << month << " " << day << " " << i << "\n";
if(a[month] >= day){
b[++bzz].month = month, b[bzz].day = day;
}
}
}
sort(b+1, b+bzz+1);
cout << bzz << "\n";
for(int i = 1; i <= bzz; i++) cout << b[i].month << " " << b[i].day << "\n";
}
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...