密度图(二维差分(修改前后加减及其坐标,半环形求值)(已完成,坐标方向反了(y,x)))

This commit is contained in:
James 2020-05-03 11:57:22 +08:00
parent 0a9a03ccec
commit c6aac5f996
5 changed files with 123 additions and 72 deletions

View File

@ -1,63 +1,70 @@
//weiwancheng
#include <cstdio>
#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
int xy,r;
int xy, r;
//bool a[251][251]={0};
int ans[252][252]={0};
cin>>xy>>r;
for(int i=1;i<=xy;i++){
for(int j=1;j<=xy;j++){
int ans[252][252] = { 0 };
cin >> xy >> r;
for (int i = 1; i <= xy; i++) {
for (int j = 1; j <= xy; j++) {
bool u;
cin>>u;
if(u==1){
printf("(%d,%d):",i,j);
int qx=i-r,qy=j-r;
int hx=i+r+1,hy=j+r+1;
if(qx<1){
qx=1;
cin >> u;
if (u == 1) {
// printf("(%d,%d):", i, j);
int qx = i - r, qy = j - r;
int hx = i + r + 1, hy = j + r + 1;
if (qx < 1) {
qx = 1;
}
if(qy<1){
qy=1;
if (qy < 1) {
qy = 1;
}
if(hx>xy){
hx=xy+1;
if (hx > xy) {
hx = xy + 1;
}
if(hy>xy){
hy=xy+1;
if (hy > xy) {
hy = xy + 1;
}
printf("%d %d %d %d ",qx,qy,hx,hy);
// printf("(%d,%d) (%d,%d) ", qx, qy, hx, hy);
ans[qx][qy]++;
ans[i][hy]--;
ans[j][hx]--;
ans[hx][hy]--;
printf("%d %d %d %d\n",ans[qx][qy],ans[i][hy],ans[j][hx],ans[hx][hy]);
ans[qx][hy]--;
ans[hx][qy]--;
ans[hx][hy]++;
// printf("(%d,%d) (%d,%d)\n", i,hy,j,hx);
}
}
}
for(int i=1;i<=xy;i++){
for(int j=1;j<=xy;j++){
// ans[i][j]+=ans[i-1][j]+ans[i][j-1]-ans[i-1][j-1];
cout<<ans[i][j];
if(j!=xy){
cout<<" ";
}else{
cout<<endl;
}
// printf("\n");
// for (int i = 1; i <= xy; i++) {
// for (int j = 1; j <= xy; j++) {
// // ans[i][j]+=ans[i-1][j]+ans[i][j-1]-ans[i-1][j-1];
// cout << ans[i][j];
// if (j != xy) {
// cout << " ";
// } else {
// cout << endl;
// }
// }
// }
// printf("\n");
for (int i = 1; i <= xy; i++) {
for (int j = 1; j <= i-1; j++) {
ans[i][j] += ans[i - 1][j] + ans[i][j - 1] - ans[i - 1][j - 1];
}
for (int j = 1; j <= i - 1; j++) {
ans[j][i] += ans[j - 1][i] + ans[j][i - 1] - ans[j - 1][i - 1];
}
ans[i][i] += ans[i - 1][i] + ans[i][i - 1] - ans[i - 1][i - 1];
}
for(int i=1;i<=xy;i++){
for(int j=1;j<=xy;j++){
ans[i][j]+=ans[i-1][j]+ans[i][j-1]-ans[i-1][j-1];
cout<<ans[i][j];
if(j!=xy){
cout<<" ";
}else{
cout<<endl;
for (int i = 1; i <= xy; i++) {
for (int j = 1; j <= xy; j++) {
cout << ans[i][j];
if (j != xy) {
cout << " ";
} else {
cout << endl;
}
}
}

Binary file not shown.

View File

@ -0,0 +1,11 @@
10 5
0 1 1 1 0 0 0 0 1 0
1 1 0 1 1 1 0 1 1 1
0 0 0 1 0 0 0 1 0 0
1 0 0 0 0 0 0 1 0 0
0 0 1 0 0 0 1 0 1 1
0 0 0 0 0 1 0 1 0 1
0 0 0 0 0 1 0 1 1 1
1 1 1 1 1 1 1 0 0 0
1 0 0 0 1 0 0 0 1 0
0 1 0 0 1 1 0 1 1 1

View File

@ -0,0 +1,21 @@
20 19
0 1 1 1 1 0 1 0 1 0 0 1 1 1 1 0 1 1 0 0
0 1 0 0 0 0 0 0 1 0 0 1 1 1 1 1 1 1 0 0
0 1 0 1 1 0 0 0 1 0 1 1 0 1 0 0 1 0 1 0
1 1 1 1 0 0 1 1 0 0 1 1 1 0 1 1 1 1 0 0
1 1 1 1 0 0 1 1 0 0 0 1 0 1 0 1 0 0 0 1
1 1 1 1 1 0 0 0 1 0 0 1 0 0 0 1 1 1 1 0
0 0 1 0 0 1 0 0 0 0 0 1 0 0 1 0 1 1 0 0
1 1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 11:51:24.21
2 2 3 4 4
3 3 3 4 4
4 4 2 2 2
4 5 3 3 2
3 4 3 3 2
-----------------------------------------------
Process exited after 160 ms with return value 0
## z:\Chao\src\2768_midupng\test\in2.txt
2020/05/02 ÖÜÁù 20:11:44.84
2020/05/03 ÖÜÈÕ 11:51:24.21
12 13 17 20 23 23 21 19 17 14
13 14 19 23 27 27 25 23 21 18
19 21 26 30 34 34 31 28 25 21
21 23 28 33 37 37 33 30 27 23
24 26 32 38 43 43 39 35 32 28
24 26 32 38 43 43 39 35 32 28
21 23 29 34 39 39 35 32 30 27
16 18 23 27 31 31 28 26 24 22
15 17 21 25 29 29 26 24 22 21
14 16 19 23 27 27 25 23 21 20
-----------------------------------------------
Process exited after 70 ms with return value 0
Process exited after 90 ms with return value 0
## z:\Chao\src\2768_midupng\test\in3.txt
2020/05/02 ÖÜÁù 20:11:44.84
2020/05/03 ÖÜÈÕ 11:51:24.21
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203 203
-----------------------------------------------
Process exited after 80 ms with return value 0
Process exited after 90 ms with return value 0