acwing_1788

3071

aoaoaoaoa

#include<bits/stdc++.h>
using namespace std;

int main(){
int n,k;
scanf("%d %d",&n,&k);
int tmp=n/k;
printf("%d",k*tmp+k);
return 0;
}


acwing_1788
2020-07-04 10:41
#include<bits/stdc++.h>
using namespace std;
const int N=(1<<20)+10;
int st[N],primes[N],minp[N];
int cnt;
typedef long long ll;
ll f[21];
void get_primes(int n){
for(int i=2;i<=n;i++){
if(!st[i]){
minp[i]=i;
primes[cnt++]=i;
st[i]=1;
}
for(int j=0;i*primes[j]<n;j++){
st[i*primes[j]]=1;
minp[i*primes[j]]=primes[j];
if(i%primes[j]==0)break;
}
}
}
int main(){
f[1]=1;
for(int i=2;i<21;i++){
f[i]=f[i-1]*i;
}
int x;
get_primes(N-1);
while(cin>>x){
ll sum=1;
ll total=0;
while(x>1){
int p=minp[x];
int k=0;
while(x%p==0)
{
k++;
total++;
x/=p;
}
sum*=f[k];
}
printf("%lld %lld\n",total,f[total]/sum);
}
return 0;
}



acwing_1788
2020-07-04 09:44
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int a[N];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++)scanf("%d",&a[i]);
sort(a,a+n);
int select;
select=n/2;
int ans=0;
for(int i=0;i<n;i++){
int t=abs(a[select]-a[i]);
//cout<<t<<endl;
ans+=t;
}
cout<<ans;
return 0;
}


acwing_1788
2020-07-04 09:30
// #include<bits/stdc++.h>
// using namespace std;
// //f[i][j][k][v]走到(i,j)处时，所有宝物的最大价值v以及件数k
// int main(){
//     cin>>n>>m>>k;//n行m列k件

//     return 0;
// }
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 55;
const int M = 15;
const int MOD = 1e9 + 7;

int n, m, c;
int a[N][N];
int f[N][N][M][M];

int main(){

scanf("%d%d%d", &n, &m, &c);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++){
scanf("%d", &a[i][j]);
a[i][j]++;
}
f[1][1][0][0] = 1;
f[1][1][1][a[1][1]] = 1;

for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
for(int cnt = 0; cnt <= c; cnt++)
for(int k = 0; k < M; k++){
//不拿物品
f[i][j][cnt][k] = (f[i][j][cnt][k] + f[i - 1][j][cnt][k]) % MOD;
f[i][j][cnt][k] = (f[i][j][cnt][k] + f[i][j - 1][cnt][k]) % MOD;

//可以拿
if(cnt > 0 && k == a[i][j]){
for(int s = 0; s < a[i][j]; s++){
f[i][j][cnt][k] = (f[i][j][cnt][k] + f[i - 1][j][cnt - 1][s]) % MOD;
f[i][j][cnt][k] = (f[i][j][cnt][k] + f[i][j - 1][cnt - 1][s]) % MOD;
}
}
}
int res = 0;
for(int i = 1; i < M; i++)
res = (res + f[n][m][c][i]) % MOD;

printf("%d\n", res);

return 0;
}



acwing_1788
2020-07-04 00:48
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++)scanf("%d",&a[i]);
sort(a,a+n);
int d=0;
for(int i=1;i<n;i++){
d=gcd(d,a[i]-a[0]);
}
if(d==0)cout<<n;
else cout<<(a[n-1]-a[0])/d+1;
return 0;
}


acwing_1788
2020-07-03 23:21

#include<bits/stdc++.h>
using namespace std;
// #define x first
// #define y second
const int N = 105;
struct point {
int x, y, z;
int step;
};
int l, r, c;
point start, endd;
char g[N][N][N];
int v[N][N][N];
int bfs() {
int ans = 0;
memset(v, 0, sizeof v);
queue<point>p;
int dx[6] = { -1,1,0,0,0,0 };
int dy[6] = { 0,0,-1,1,0,0 };
int dz[6] = { 0,0,0,0,1,-1 };
v[start.z][start.x][start.y] = 1;
start.step = 0;
p.push(start);
while (p.size()) {
point t = p.front();
for (int i = 0; i < 6; i++) {
int x = dx[i] + t.x, y = dy[i] + t.y, z = dz[i] + t.z;
//cout << x << "-" << y << "-" << z << endl;
if (x < 0 || y < 0 || z<0 || x >= r || y >= c || z>l)continue;
if (v[z][x][y])continue;
if (g[z][x][y] == '.'||(x == endd.x && y == endd.y && z == endd.z)) {
point temp;
temp.x = x; temp.y = y; temp.z = z; temp.step = t.step + 1;
v[z][x][y] = 1;
p.push(temp);
//cout << p.size() << endl;
if (x == endd.x && y == endd.y && z == endd.z)return temp.step;
//ans++;
}
else {
continue;
}
}
p.pop();
}
return -1;
}
int main() {
//cin>>l>>r>>c;
while (scanf("%d%d%d", &l, &r, &c) && r && c && l) {

int x = l;
while (x) {
for (int i = 0; i < r; i++)scanf("%s", g[x][i]);
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++) {
if (g[x][i][j] == 'S') { start.x = i, start.y = j; start.z = x; }
if (g[x][i][j] == 'E') { endd.x = i, endd.y = j; endd.z = x; }
}
x--;
}
//cout << "1" << endl;
//cout<<g[2][1][0]<<endl;

//cout << start.x << "--" << start.y << "--" << start.z << endl;
//cout << endd.x << "--" << endd.y << "--" << endd.z << endl;

int tim = bfs();
if (tim != -1)printf("Escaped in %d minute(s).\n", tim);
else printf("Trapped!\n");

}
//cout << "2" << endl;
return 0;
}



acwing_1788
2020-07-03 22:25
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int a[N];
int ans;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++)scanf("%d",&a[i]);
for(int i=0;i+1<n;i++){
int delta=a[i+1]-a[i];
if(delta>0)
ans+=delta;
}
cout<<ans;
return 0;
}


acwing_1788
2020-07-03 21:19
#include<bits/stdc++.h>
using namespace std;
int n;
const int N=100010;
int inf=0x3f3f3f3f;
int a[N];
long long b[N];
int main(){
memset(b,0,sizeof b);
cin>>n;
int j=1;
long long maxx=-inf;
for(int i=1;i<=n;i++){scanf("%d",&a[i]);
}
//cout<<cnt<<endl;;
for(int i=1;i<=n;){
while((i<pow(2,j))&&(i<=n)){
b[j]+=a[i++];
}
maxx=max(maxx,b[j]);
j++;
}
//for(int i=1024;i<=10000;i++)cout<<a[i]<<"-";
int ans=0;
//cout<<j<<endl;
for(int i=1;i<=j;i++){
//cout<<b[i]<<endl;
if(b[i]==maxx){
ans=i;
break;
}
}
cout<<ans;
return 0;
}


acwing_1788
2020-07-03 20:36
#include<bits/stdc++.h>
using namespace std;

const int N=10010;
int a[N];
int n;
int find(int x,int l){
for(int i=l;i<=n;i++)
if(x==a[i])return i;
return -1;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
int b[N];
memcpy(b,a,sizeof a);
sort(b+1,b+1+n);
int cnt=0;
for(int i=1;i<=n;i++){
if(a[i]!=i){
int x=find(i,i);
//cout<<x<<endl;
a[x]=a[i];
cnt++;
}
}
cout<<cnt<<endl;
return 0;
}