A Groundhog and 2-Power Representation
题目传送门
Groundhog and 2-Power Representation
思路
大数,python,直接在计算幂的地方替换python的幂次计算(**),然后用eval函数计算即可
AC Code
print(eval(str(input()).replace('(', '**(')))
I The Crime-solving Plan of Groundhog
题目传送门
The Crime-solving Plan of Groundhog
思路
显然两个数字相差越大,乘积越小,所以需要找到第一个不为0的数字成为第一个数,第二个不为0的数字为第二个数的开头,后面接上0和其他非递减的数
AC Code
.cpp
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
// #define TDS_ACM_LOCAL
const int N=2e5 +9;
int n;
int a[N];
void solve(){
cin>>n;
for(int i=1; i<=n; i++) cin>>a[i];
sort(a+1, a+1+n);
int pos=0;
while(!a[++pos]);
swap(a[1], a[pos]), swap(a[2], a[pos+1]);
for(int i=2; i<=n; i++) a[i]*=a[1];
for(int i=n; i>2; i--) a[i-1]+=a[i]/10, a[i]%=10;
for(int i=2; i<=n; i++) cout<<a[i];
cout<<endl;
return ;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#ifdef TDS_ACM_LOCAL
freopen("D:\\VS code\\.vscode\\testall\\in.txt", "r", stdin);
freopen("D:\\VS code\\.vscode\\testall\\out.txt", "w", stdout);
#endif
int T;
cin>>T;
while(T--) solve();
return 0;
}
.py
T=int(input())
while T:
T-=1
n=int(input())
a=input().split()
a.sort()
pos=0
while a[pos]=='0':
pos+=1
x=a[pos]
y=a[pos+1]+'0'*pos+''.join(a[pos+2:])
print(int(x)*int(y))
F Groundhog Looking Dowdy
题目传送门
题目大意
给你n天,n天中每天都有k件衣服,衣服具有权值
你需要选择其中的m天,使得衣服的最大权值和最小权值差最小
思路
显然的尺取,开个vector记录没件衣服的权值和来源(天数),然后按照权值排序后,再用滑动窗口维护一个天数为m的区间即可
AC Code
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
// #define TDS_ACM_LOCAL
const int N=2e6 +9;
int n, m, k, vis[N], x;
vector<pair<int,int>>a;
void solve(){
cin>>n>>m;
for(int i=1; i<=n; i++){
cin>>k;
for(int j=0; j<k; j++){
cin>>x;
a.emplace_back(x,i);
}
}
sort(a.begin(), a.end());
int r=0, now=0, ans=INF, len=a.size();
for(int l=0; l<len; l++){
while( r<len && now<m ){ //当前衣服的天数不到m
if(!vis[a[r].second]) now++; //该件衣服的天数没出现过就记录
vis[a[r].second]++; //vis-当前衣服的天数出现的次数
r++;
}
if(now==m) ans=min(ans, a[r-1].first-a[l].first); //当前维护的区间的最小值
vis[a[l].second]--; //l右移的状态改变
if(!vis[a[l].second]) now--;
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#ifdef TDS_ACM_LOCAL
freopen("D:\\VS code\\.vscode\\testall\\in.txt", "r", stdin);
freopen("D:\\VS code\\.vscode\\testall\\out.txt", "w", stdout);
#endif
solve();
return 0;
}