暑期第6-8周解题报告5篇(8月16日-9月5日)
#include<iostream>
#include<vector>
#include<algorithm>
#define int long long
typedef long long ll;
using namespace std;
vector<int>v[60];
int a,b,c,d,n;
int calg(int x){
int ans=0;
while(x){
ans=ans+x%10;
x=x/10;
}
return ans;
}
int calc(int x){
int g=calg(x);
return (a*g+b)*x*x+(c*g*g+d*g)*x;
}
void init(){
for(int i=1;i<=1000000;i++){
v[calg(i)].push_back(i);
}
}
signed main(){
init();
int t;
cin >> t;
while(t--){
cin >> a >> b >> c >> d >> n;
int ans=0x3f3f3f3f;
for(int i=1;i<=54;i++){
int A=a*i+b;
int B=c*i*i+d*i;
if(A==0) continue;
int dcz=(-B)/(2*A);
if(dcz<=1) continue;
int temp=upper_bound(v[i].begin(),v[i].end(),dcz)-v[i].begin();
int bound=upper_bound(v[i].begin(),v[i].end(),n)-v[i].begin();
if(temp<bound&&temp>=1&&v[i][temp]<=n){
ans=min(calc(v[i][temp]),ans);
}
if(temp-1<bound&&temp-1>=0&&v[i][temp-1]<=n){
ans=min(calc(v[i][temp-1]),ans);
}
}
for(int i=1;i<=54;i++){
int x1=v[i][0];
if(x1>n) break;
int x2=v[i][upper_bound(v[i].begin(),v[i].end(),n)-v[i].begin()-1];
ans=min(calc(x1),ans);
ans=min(calc(x2),ans);
}
cout << ans << endl;
}
}
#include<iostream>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int k=n/4;
int x=n%4;
if(x==1) cout << 4*k+1 << endl << "1";
else if(x==2) cout << 4*k+4 << endl << "0001";
else if(x==3) cout << 4*k+2 << endl << "01";
else cout << 4*k << endl;
while(k--){
cout << "1001";
}
cout << endl;
}
return 0;
}
#include<iostream>
#include<algorithm>
#define int long long
typedef long long ll;
using namespace std;
const int N=1e5+5;
struct node{
int num;
int ma;
}a[N];
bool cmp(node a,node b){
if(a.ma==b.ma){
return a.num>b.num;
}
return a.ma<b.ma;
}
signed main()
{
int t;
cin >> t;
while(t--){
int n;
cin >> n;
for(int i=1;i<=n;i++){
int x;cin >> x;
int maxx=0;
a[i].num=x;
for(int j=1;j<=x;j++){
int m;cin >> m;
maxx=max(maxx,m-j+2);
}
a[i].ma=maxx;
}
sort(a+1,a+1+n,cmp);
int res=0;
int now=0;
for(int i=1;i<=n;i++){
if(now>=a[i].ma){
now=now+a[i].num;
}
else{
res=res+a[i].ma-now;
now=a[i].ma+a[i].num;
}
}
cout << res << endl;
}
return 0;
}
#include<iostream>
#define int long long
typedef long long ll;
using namespace std;
const int N=2e5+5;
int dp[N];
signed main()
{
int n,mod;
cin >> n >> mod;
dp[1]=1;
int sum=dp[1];
for(int i=2;i<=n;i++){
dp[i]=(dp[i]%mod+sum%mod)%mod;
for(int l=2,r=0;l<=i;l=r+1){
r=i/(i/l);
dp[i]=(dp[i]%mod+dp[i/l]*(r-l+1)%mod)%mod;
}
sum=(sum%mod+dp[i]%mod)%mod;
}
cout << dp[n] << endl;
return 0;
}
#include<iostream>
#include<algorithm>
using namespace std;
const int N=15;
int n;
int a[N];
int group[N][N];
int vis[N];
int ans;
int flag;
bool check(int group[],int gc,int i){
for(int j=0;j<gc;j++){
if(__gcd(a[group[j]],a[i])>1){
return 0;
}
}
return 1;
}
void dfs(int g,int gc,int x,int st){
if(g>=ans){
return;
}
if(x==n){
ans=g;
}
flag=1;
for(int i=st;i<n;i++){
if(!vis[i] && check(group[g],gc,i)){
vis[i]=1;
group[g][gc]=i;
dfs(g,gc+1,x+1,i+1);
vis[i]=0;
flag=0;
}
}
if(flag){
dfs(g+1,0,x,0);
}
}
int main()
{
cin >> n;
for(int i=0;i<n;i++){
cin >> a[i];
}
ans=n;
dfs(1,0,0,0);
cout << ans << endl;
return 0;
}