vanilla

3290

vanilla
2019-05-26 13:48

题目描述

1≤n,m≤1000,
1≤q≤100000,
1≤x1≤x2≤n,
1≤y1≤y2≤m,
−1000≤c≤1000,
−1000≤矩阵内元素的值≤1000

3 4 3
1 2 2 1
3 2 2 1
1 1 1 1
1 1 2 2 1
1 3 2 3 2
3 1 3 4 1

2 3 4 1
4 3 4 1
2 2 2 2

C++ 代码

#include<iostream>
#include<cstdio>
using namespace std;
const int MAX_N = 1e3+5;
int a[MAX_N][MAX_N] = {0};
int s[MAX_N][MAX_N] = {0};
void insert(int x1,int y1,int x2,int y2,int v){
a[x1][y1] += v;
a[x2+1][y1] -= v;
a[x1][y2+1] -= v;
a[x2+1][y2+1] += v; //多减一次，加v进行抵消操作
}
int main(){
int n,m,q;
scanf("%d%d%d",&n,&m,&q);
for(int i = 1; i <= n; i++){
for(int j = 1;j <= m; j++){
int t;
scanf("%d",&t);
insert(i,j,i,j,t);
}
}
while(q--){
int x1,y1,x2,y2,t;
scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&t);
insert(x1,y1,x2,y2,t);
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + a[i][j];
printf("%d",s[i][j]);
if(j != m)
printf(" ");
}
if(i!= n)
printf("\n");
}
return 0;
}


vanilla
2019-05-07 15:30
#include<bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MAX_N = 21;
int temp[MAX_N][MAX_N] = {0};
int dp[1<<MAX_N][MAX_N];
int main(){
memset(dp,inf,sizeof(dp));
int n;
scanf("%d",&n);
for(int i = 0 ;i  < n; i++)
for(int j = 0; j < n; j++)
scanf("%d",&temp[i][j]);

dp[1][0] = 0;
for(int i = 1; i <(1<< n); i++){
for(int j = 0; j < n; j++){
if((i>>j & 1)){
for(int k = 0; k < n; k++){
if((i^(1<<j))>>k & 1)
dp[i][j] = min(dp[i][j],dp[i^(1<<j)][k] + temp[k][j]);
}
}
}
}
printf("%d\n",dp[(1<<n)-1][n-1]);
return 0;
}



vanilla
2019-05-06 16:55
#include<iostream>
#include<cstdio>
using namespace std;
typedef unsigned long long int ll;
void mod_add(ll x, ll n, ll p){
ll res = 0;
while(n){
if(n & 1) res = (res + x) % p;
x = (x<<1)%p;
n >>= 1;
}
cout<<res<<endl;
}
int main(){
ll a,b,p;
cin>>a>>b>>p;
return 0;
}



vanilla
2019-05-06 16:11
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<string>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define MAX_N 1000005
#define gcd(a,b) __gcd(a,b)
#define mem(a,x) memset(a,x,sizeof(a))
#define mid(a,b) a+b/2
#define stol(a) atoi(a.c_str())//string to long
int temp[MAX_N];
void mod_power(ll x, ll n, ll mod){
ll res = 1;
while(n){
if(n & 1) res = res * x % mod;
x <<= 1;
n >>= 1;
}
printf("%lld\n",res);
}
int main(){
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
//    #ifndef ONLINE_JUDGE
//        freopen("D:\\in.txt","r",stdin);
//        freopen("D:\\out.txt","w",stdout);
//    #else
//    #endif
ll a,b,c;
cin>>a>>b>>c;
mod_power(a,b,c);
return 0;
}