Magical Forest

本文解析了一道关于离散化模拟的算法题,题目涉及一个由N*M网格构成的森林地图,地图上有若干能量水果,需通过交换行或列来获取指定位置的能量水果信息。文章提供了完整的代码实现及解析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Description
There is a forest can be seen as N * M grid. In this forest, there is some magical fruits, These fruits can provide a lot of energy, Each fruit has its location(Xi, Yi) and the energy can be provided Ci.

However, the forest will make the following change sometimes:
1. Two rows of forest exchange.
2. Two columns of forest exchange.
Fortunately, two rows(columns) can exchange only if both of them contain fruits or none of them contain fruits.

Your superior attach importance to these magical fruit, he needs to know this forest information at any time, and you as his best programmer, you need to write a program in order to ask his answers quick every time.
 


Input
The input consists of multiple test cases.

The first line has one integer W. Indicates the case number.(1<=W<=5)

For each case, the first line has three integers N, M, K. Indicates that the forest can be seen as maps N rows, M columns, there are K fruits on the map.(1<=N, M<=2*10^9, 0<=K<=10^5)

The next K lines, each line has three integers X, Y, C, indicates that there is a fruit with C energy in X row, Y column. (0<=X<=N-1, 0<=Y<=M-1, 1<=C<=1000)

The next line has one integer T. (0<=T<=10^5)
The next T lines, each line has three integers Q, A, B.
If Q = 1 indicates that this is a map of the row switching operation, the A row and B row exchange.
If Q = 2 indicates that this is a map of the column switching operation, the A column and B column exchange.
If Q = 3 means that it is time to ask your boss for the map, asked about the situation in (A, B).
(Ensure that all given A, B are legal. )
Output
For each case, you should output "Case #C:" first, where C indicates the case number and counts from 1.

In each case, for every time the boss asked, output an integer X, if asked point have fruit, then the output is the energy of the fruit, otherwise the output is 0
input
1
3 3 2
1 1 1
2 2 2
5
3 1 1
1 1 2
2 1 2
3 1 1
3 2 2
output
Case #1:
1
2
1
考察离散化的模拟题。
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <map>
 4 #include <algorithm>
 5 
 6 using namespace std;
 7 
 8 struct Node
 9 {
10     int x;
11     int y;
12     int c;
13 }l[100000];
14 
15 map <int, map<int, int> > fmap;
16 map <int ,int>hashx,hashy;
17 int T,n,m,k,mapx,mapy,t,cas,lianx[100010],liany[100010],Q,A,B,X,Y;
18 
19 bool cmpx(Node a,Node b)
20 {
21     return a.x<b.x;
22 }
23 bool cmpy(Node a,Node b)
24 {
25     return a.y<b.y;
26 }
27 
28 int main()
29 {
30     int CAS;
31     scanf("%d", &CAS);
32     for(int cas=1;cas<=CAS;cas++)
33     {
34       scanf("%d%d%d",&n,&m,&k);
35       printf("Case #%d:\n",cas);
36       for(int i=0;i<k;i++)scanf("%d%d%d",&l[i].x,&l[i].y,&l[i].c);
37       fmap.clear();hashx.clear();hashy.clear();mapx=mapy=0;
38       sort(l,l+k,cmpx);
39       for(int i=0;i<k;i++)if(!hashx[l[i].x])hashx[l[i].x]=++mapx;
40       sort(l,l+k,cmpy);
41       for(int i=0;i<k;i++)
42       {
43         if(!hashy[l[i].y])hashy[l[i].y]=++mapy;
44         fmap[hashx[l[i].x]][hashy[l[i].y]]=l[i].c;
45       }
46       for(int i=1;i<=mapx;i++)lianx[i]=i;
47       for(int i=1;i<=mapy;i++)liany[i]=i;
48       scanf("%d",&t);
49       for(int i=0;i<t;i++)
50       {
51         scanf("%d%d%d",&Q,&A,&B);
52         if(Q==1)
53         {
54           X=hashx[A];Y=hashx[B];
55           if(X && Y)swap(lianx[X],lianx[Y]);
56         }
57         else if(Q==2)
58         {
59           X=hashy[A];Y=hashy[B];
60           if(X && Y)swap(liany[X],liany[Y]);
61         }
62         else if(Q==3)
63         {
64           X=hashx[A];Y=hashy[B];
65           if(X && Y)printf("%d\n",fmap[lianx[X]][liany[Y]]);
66           else printf("0\n");
67         }
68       }
69     }
70     return 0;
71 }

 

转载于:https://www.cnblogs.com/767355675hutaishi/p/3908406.html

### 在MidJourney中使用角色参考参数生成自定义人物形象 在MidJourney中,可以通过`--sref`和`--cref`参数来实现对生成图像中的人物进行替换或调整为用户提供的角色。以下是对这些参数的详细说明以及如何正确使用的教程。 #### 参数解释 - `--sref`:此参数用于指定风格参考图,通过上传一张图片链接,可以指导AI根据该图片的风格生成新图像[^2]。 - `--cref`:此参数用于指定内容参考图,主要用于定义生成图像中的具体角色或元素[^1]。 当希望将生成图像中的人物更换为自己提供的角色时,主要依赖`--cref`参数来提供角色的具体外观特征,而`--sref`则可以用来保持原有动作、场景或其他视觉元素的一致性。 #### 示例命令结构 以下是一个完整的示例命令,展示如何结合`--sref`和`--cref`参数生成带有自定义角色的图像: ```plaintext /imagine prompt:A fantasy warrior standing in a magical forest --sref https://example.com/style.jpg --cref https://example.com/character.jpg ``` 在此命令中: - `A fantasy warrior standing in a magical forest` 是描述性的文本提示,定义了整体场景和氛围。 - `--sref https://example.com/style.jpg` 提供了一个风格参考图,确保生成图像具有与该参考图相似的艺术风格。 - `--cref https://example.com/character.jpg` 提供了一个角色参考图,用以替换默认生成的人物形象,使其更接近用户提供的角色外观。 #### 参数调整技巧 为了进一步优化生成结果,还可以结合其他参数使用,例如: - `--ar`:调整生成图像的宽高比,以适应不同应用场景的需求[^2]。 - `--s`:控制风格化程度,数值越高则越强调艺术风格而非写实效果。 #### 注意事项 在实际操作过程中需要注意以下几点: - 确保提供的参考图清晰且包含足够的细节信息,以便AI能够准确理解所需风格或角色特征。 - 如果生成结果不符合预期,可以尝试微调提示词或更换参考图,多次迭代直至达到理想效果。 ```python # 示例代码块:自动化生成命令脚本 def generate_command(prompt, style_ref, character_ref): return f"/imagine prompt:{prompt} --sref {style_ref} --cref {character_ref}" # 调用函数生成命令 command = generate_command("A futuristic cyborg in an urban environment", "https://example.com/futuristic_style.jpg", "https://example.com/cyborg_character.jpg") print(command) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值