GVKun编程网logo

delphi – 为什么TForm.SetBounds仅在设计时将TForm.Position设置为poDefault时才能正常工作

9

对于delphi–为什么TForm.SetBounds仅在设计时将TForm.Position设置为poDefault时才能正常工作感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于Causedb

对于delphi – 为什么TForm.SetBounds仅在设计时将TForm.Position设置为poDefault时才能正常工作感兴趣的读者,本文将会是一篇不错的选择,并为您提供关于Caused by: java.lang.ClassNotFoundException: kafka.DefaultSource、Caused by: java.lang.ClassNotFoundException: org.springframework.web.filter.FormContentFilter、Codeforces 1082 C. Multi-Subject Competition-有点意思 (Educational Codeforces Round 55 (Rated for Div...、codeforces 981 C.Useful Decomposition的有用信息。

本文目录一览:

delphi – 为什么TForm.SetBounds仅在设计时将TForm.Position设置为poDefault时才能正常工作

delphi – 为什么TForm.SetBounds仅在设计时将TForm.Position设置为poDefault时才能正常工作

我注意到一些非常奇怪的事情.我在表单关闭时保持表单的top,left,width和height属性,并使用此信息通过使用以前存储的信息调用SetBounds再次打开表单时恢复表单的最后位置.这很有效,但前提是表单的Position属性在设计时设置为podefault.如果设置为其他内容,例如podesigned,poScreenCenter或poMainFormCenter,则SetBounds不会恢复表单的先前位置和大小.

这是奇怪的部分.看似重要的是在设计时将Position属性设置为什么.我可以在运行时将此属性的值更改为podefault,并且对SetBounds的调用仍然无法正常工作.我尝试过类似下面的内容

if Self.Position <> podefault then
  Self.Position := podefault;

在表单的OnCreate事件处理程序中,以及从重写的构造函数(并在构造函数中将Position设置为podefault,并在OnCreate事件处理程序中调用SetBounds).在所有情况下,在运行时将表单的Position属性更改为podefault并不能解决我在SetBounds中观察到的问题.我发现的唯一一致模式是SetBounds只有在设计时表单的Position属性为podefault才能正常工作.

当表单的Position属性在设计时未设置为podefault时,还有其他一些我注意到SetBounds的工作原理.例如,如果调用SetBounds,则在设计时将Position属性设置为poScreenCenter的表单不一定会显示在屏幕的中心.但是,它不会出现在由SetBounds定义的左上角位置,也不会出现在调用SetBounds时指定的宽度和高度.但是,让我重复一遍,我在调用SetBounds之前将表单的Position属性设置为podefault.我甚至在两个操作之间调用了Application.ProcessMessages,但这并没有解决问题.

我已经在Windows 10上运行Delphi 10.1 Berlin进行了广泛的测试.我还在Windows 7上使用Delphi XE6对其进行了测试.结果相同.

如果您有疑问,请创建一个包含四种表单的VCL应用程序.在第一个表单上放置三个按钮,并为每个按钮添加如下OnClick:

with TForm2.Create(nil) do
 try
   ShowModal;
 finally
   Release;
 end;

构造函数创建TForm2,然后TForm3和TForm4.

在表单2到4的OnCreate上,添加以下代码:

if Self.Position <> podefault then
  Self.Position := podefault;
Self.SetBounds(500,500,500);

在form2上,将Position设置为podefault,在form3上将Position设置为poScreenCenter,并在form4上将Position设置为默认值podefaultPosOnly.只有form2将出现在500,宽度为500,高度为500.

有没有人对这个结果有合理的解释?

解决方法

podefault和朋友的意思是“当窗体创建并显示它时,让Microsoft Windows定位此窗体的窗口”.

你刚刚创建了Delphi对象 – 但我想知道它是否也创建/显示了Windows对象(HWND句柄和所有相应的Windows内部结构).特别是对于使用主题应用程序,而不是使用标准的XP前外观 – 它们在显示时倾向于ReCreateHWND,因为预加载那些花哨的Windows主题是相对昂贵的操作,只应在需要时完成.

我认为您的默认边界(构造函数中设置的每个属性值可能被视为默认的非调整值,在构造对象后稍后调整)会被正确忽略(或者TApplication – 这对主题没什么影响)做FormXXX.Show.

当你的表单查看其属性时,它会在“让我成为一个窗口并显示它”序列中,并告诉MS Windows“现在我想创建你的内部HWND对象,并根据你的判断将它定位在默认坐标/大小” .

这是绝对正确的行为 – 否则何时和TFOW如何应用Position属性???向Windows询问屏幕上不存在的窗口的坐标是没有意义的,也许永远不会. Windows提供默认的坐标/尺寸,查看它的第二个窗口,查看有多少其他窗口以及它们的位置(AMD / NVidia视频驱动程序也可能对它进行校正).

现在获取默认值并在两小时之后应用它们毫无意义,一切都可能不同 – 不同数量的其他窗口和不同的位置,不同的监视器组和不同的分辨率等.

只考虑一种“台式机替代”类型的笔记本电脑.它被安装在连接到大型固定外部监视器的桌子上.然后 – 让我们想象一下 – 我运行你的应用程序,它创建了tform Delphi对象,并在构造函数中询问了MS Windows的位置 – 而Windows正确地提供了该次要大型监视器的位置.但是一个小时之后我拔掉了笔记本电脑并随便走开了.现在一小时后我告诉你的应用程序显示表单 – 它会做什么?用属于现在分离的外部显示器的坐标显示它?在笔记本内部显示器的视口之外,我目前只有这个显示器?这个表单应该显示在现在的“隐形”位置,因为当我启动应用程序时,那个地方仍然可见吗?我认为,混淆用户无益的方法.

因此,唯一正确的行为是在窗体从隐藏到可见而不是之前的第二个时,请求Windows提供默认坐标.

这意味着如果你想要移动你的表单 – 你应该在它显示后进行.放置Self.SetBounds(500,500);进入OnShow事件处理程序.因此,让MS Windows将您的表单实现为默认位置,就像位置属性中的podefault所需 – 并在此之后移动您的Window.试图移动不存在的窗口看起来对我来说是徒劳的.

预设你的表单(在构造序列中)以明确地忽略MS Windows默认值并使用预设的线(通过podesigned值),或者让表单询问Windows坐标,但是在通过OnShow处理程序可见之后使用SetBounds移动它.

Caused by: java.lang.ClassNotFoundException: kafka.DefaultSource

Caused by: java.lang.ClassNotFoundException: kafka.DefaultSource

Started o.s.j.s.ServletContextHandler@49096b06{/static/sql,null,AVAILABLE}
Exception in thread "main" java.lang.ClassNotFoundException: Failed to find data source: kafka. Please find packages at http://spark.apache.org/third-party-projects.html
    at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:569)
    at org.apache.spark.sql.execution.datasources.DataSource.providingClass$lzycompute(DataSource.scala:86)
    at org.apache.spark.sql.execution.datasources.DataSource.providingClass(DataSource.scala:86)
    at org.apache.spark.sql.execution.datasources.DataSource.sourceSchema(DataSource.scala:197)
    at org.apache.spark.sql.execution.datasources.DataSource.sourceInfo$lzycompute(DataSource.scala:87)
    at org.apache.spark.sql.execution.datasources.DataSource.sourceInfo(DataSource.scala:87)
    at org.apache.spark.sql.execution.streaming.StreamingRelation$.apply(StreamingRelation.scala:30)
    at org.apache.spark.sql.streaming.DataStreamReader.load(DataStreamReader.scala:124)
    at org.apache.spark.examp.JavaKafkaWordCountDataRow.main(JavaKafkaWordCountDataRow.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmitrunMain(SparkSubmit.scala:738)atorg.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:187)atorg.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:212)atorg.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:126)atorg.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)Causedby:java.lang.ClassNotFoundException:kafka.DefaultSourceatjava.net.URLClassLoader.findClass(URLClassLoader.java:381)atjava.lang.ClassLoader.loadClass(ClassLoader.java:424)atjava.lang.ClassLoader.loadClass(ClassLoader.java:357)atorg.apache.spark.sql.execution.datasources.DataSource

anonfun$25anonfun$apply$13.apply(DataSource.scala:554)atorg.apache.spark.sql.execution.datasources.DataSource
anonfun$25anonfun$apply$13.apply(DataSource.scala:554)atscala.util.Try$.apply(Try.scala:192)atorg.apache.spark.sql.execution.datasources.DataSource
anonfun$25.apply(DataSource.scala:554)
    at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$25.apply(DataSource.scala:554)
    at scala.util.Try.orElse(Try.scala:84)
    at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:554)
    ... 17 more
17/07/01 19:43:30 INFO spark.SparkContext: Invoking stop() from shutdown hook
 

Caused by: java.lang.ClassNotFoundException: org.springframework.web.filter.FormContentFilter

Caused by: java.lang.ClassNotFoundException: org.springframework.web.filter.FormContentFilter

又是一个报错,我写代码真的是可以,所有的 bug 都会被我遇到,所有的问题我都能踩一遍,以前上学的时候同学就喜欢问我问题,因为他们遇到的问题,我早就遇到了.........

看看报错内容:

2019-04-04 12:01:39.612 ERROR 12628 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration.mbeanExporter

Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]

Caused by: java.lang.NoClassDefFoundError: org/springframework/web/filter/FormContentFilter

java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]

Caused by: java.lang.NoClassDefFoundError: org/springframework/web/filter/FormContentFilter

这个是我截取的报错的一部分内容,讲真,Idea 的报错我是看不懂的,看不懂,不知道怎么下手,但是我还是找到了问题所在,答案就是我的 Maven 文件的错误

我的 Maven 引用里混入了下面这个包,就是因为这个,才会报上面的错。不懂下面这个包是干嘛的,看名字应该是 Java Web 的 web 包。我新建的是 SpringBoot 项目

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.0.8.RELEASE</version>
            <scope>compile</scope>
        </dependency>

删除了这个包的引用就可以了。

Codeforces 1082 C. Multi-Subject Competition-有点意思 (Educational Codeforces Round 55 (Rated for Div...

Codeforces 1082 C. Multi-Subject Competition-有点意思 (Educational Codeforces Round 55 (Rated for Div...

C. Multi-Subject Competition
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A multi-subject competition is coming! The competition has mm different subjects participants can choose from. That''s why Alex (the coach) should form a competition delegation among his students.

He has nn candidates. For the ii-th person he knows subject sisi the candidate specializes in and riri — a skill level in his specialization (this level can be negative!).

The rules of the competition require each delegation to choose some subset of subjects they will participate in. The only restriction is that the number of students from the team participating in each of the chosen subjects should be the same.

Alex decided that each candidate would participate only in the subject he specializes in. Now Alex wonders whom he has to choose to maximize the total sum of skill levels of all delegates, or just skip the competition this year if every valid non-empty delegation has negative sum.

(Of course, Alex doesn''t have any spare money so each delegate he chooses must participate in the competition).

Input

The first line contains two integers nn and mm (1n1051≤n≤105, 1m1051≤m≤105) — the number of candidates and the number of subjects.

The next nn lines contains two integers per line: sisi and riri (1sim1≤si≤m, 104ri104−104≤ri≤104) — the subject of specialization and the skill level of the ii-th candidate.

Output

Print the single integer — the maximum total sum of skills of delegates who form a valid delegation (according to rules above) or 00 if every valid non-empty delegation has negative sum.

Examples
input
Copy
6 3
2 6
3 6
2 5
3 5
1 9
3 1
output
Copy
22
input
Copy
5 3
2 6
3 6
2 5
3 5
1 11
output
Copy
23
input
Copy
5 2
1 -1
1 -5
2 -1
2 -1
1 -10
output
Copy
0
Note

In the first example it''s optimal to choose candidates 11, 22, 33, 44, so two of them specialize in the 22-nd subject and other two in the 33-rd. The total sum is 6+6+5+5=226+6+5+5=22.

In the second example it''s optimal to choose candidates 11, 22 and 55. One person in each subject and the total sum is 6+6+11=236+6+11=23.

In the third example it''s impossible to obtain a non-negative sum.

 

 

题意就是选科目,每科人数必须相同,总和尽量大。

有一个坑,可以往里面加入负数,只要该科总和>0就可以,具体代码。

 

代码:

 1 //C
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 typedef long long ll;
 5 const int maxn=1e5+10;
 6 const int inf=0x3f3f3f3f;
 7 
 8 vector<int> ve[maxn];
 9 vector<ll> sum[maxn];
10 int sz[maxn];
11 ll ans[maxn];
12 
13 bool cmp(int a,int b)
14 {
15     return a>b;
16 }
17 
18 int main()
19 {
20     int n,m;
21     cin>>n>>m;
22     for(int i=1;i<=n;i++){
23         int s,r;
24         cin>>s>>r;
25         ve[s].push_back(r);
26     }
27     for(int i=1;i<=m;i++)
28         sort(ve[i].begin(),ve[i].end(),cmp);
29     for(int i=1;i<=m;i++){
30         int pre=0;
31         for(int j=0;j<ve[i].size();j++){
32             if(j==0) sum[i].push_back(ve[i][j]),pre=ve[i][j];
33             else sum[i].push_back(pre+ve[i][j]),pre=sum[i][j];
34         }
35     }
36     int maxx=0;
37     for(int i=1;i<=m;i++){
38         maxx=max(maxx,(int)ve[i].size());
39         for(int j=0;j<ve[i].size();j++){
40             ans[j]=max(ans[j],ans[j]+sum[i][j]);
41         }
42     }
43     ll ret=0;
44     for(int i=0;i<maxx;i++)
45         ret=max(ret,ans[i]);
46     cout<<ret<<endl;
47 }

 

 

 

codeforces 981 C.Useful Decomposition

codeforces 981 C.Useful Decomposition

C. Useful Decomposition
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!

He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!

The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two paths have at least one common vertex. Each edge of the tree should be in exactly one path.

Help Remesses, find such a decomposition of the tree or derermine that there is no such decomposition.

Input

The first line contains a single integer $n

$ ($2n105
$) the number of nodes in the tree.

Each of the next $n1

$ lines contains two integers $ai
$ and $bi
$ ($1ai,bin
$, $aibi
$) — the edges of the tree. It is guaranteed that the given edges form a tree.

Output

If there are no decompositions, print the only line containing "No".

Otherwise in the first line print "Yes", and in the second line print the number of paths in the decomposition $m

$.

Each of the next $m

$ lines should contain two integers $ui
$, $vi
$ ($1ui,vin
$, $uivi
$) denoting that one of the paths in the decomposition is the simple path between nodes $ui
$ and $vi
$.

Each pair of paths in the decomposition should have at least one common vertex, and each edge of the tree should be presented in exactly one path. You can print the paths and the ends of each path in arbitrary order.

If there are multiple decompositions, print any.

Examples
Input
4
1 2
2 3
3 4
Output
Yes
1
1 4
Input
6
1 2
2 3
3 4
2 5
3 6
Output
No
Input
5
1 2
1 3
1 4
1 5
Output
Yes
4
1 2
1 3
1 4
1 5
Note

The tree from the first example is shown on the picture below: The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.

The tree from the second example is shown on the picture below: We can show that there are no valid decompositions of this tree.

The tree from the third example is shown on the picture below: The number next to each edge corresponds to the path number in the decomposition. It is easy to see that this decomposition suits the required conditions.

 

【题意】
给一个无向边的树,要求拆成若干条简单路径,并且这些路径都经过一个公共点。给出任意一个解决方案,如不存在输出 No。

【分析】
所有的路径都有公共点,如果解决方案存在的话,那么倒着推回去,把公共点看成根节点,这棵树一定是所有的路径都从根结点出发,且都不分叉的,因为在满足这个性质时才能拆分,如果不满足,则一定有一条路径不经过根节点。
所以检查一棵树能否拆分,只用检查分叉点是否唯一就行了。而拆下来的路径,一端一定是根结点,而另一端就是这个树的所有叶子结点。

【代码】

#include<stdio.h>
#define N_max 100005

int cnt[N_max] = { 0 };//记录所有点的度数
int end[N_max] = { 0 }, ne=0;//记录所有端点序号

int main() {
	int n;
	scanf("%d", &n);
	int a1, a2;
	for (int i = 0; i < n - 1; ++i) {
		scanf("%d %d", &a1, &a2);
		cnt[a1]++;
		cnt[a2]++;
	}
	//检查分叉处是否唯一,并记录到aim
	int aim = -1;
		for (int i = 1; i <= n; ++i) {
			if (cnt[i] >= 3) {
				if (aim == -1) aim = i;
				else {
					printf("No");
					return 0;
				}
			}
			//顺带记录端点
			if (cnt[i] == 1)end[ne++]=i;
		}

	printf("Yes\n");
	//没有分叉,只有一条路径,直接输出两端
	if (aim == -1) {
		printf("1\n%d %d\n",end[0] ,end[1]);
		return 0;
	}
	//将分叉点看成根节点,每一条边都是从根出发的,拆下来就行了
	printf("%d\n", ne);
	for (int t = 0; t < ne; ++t) {
		printf("%d %d\n", aim, end[t]);
	}
	return 0;
}

今天关于delphi – 为什么TForm.SetBounds仅在设计时将TForm.Position设置为poDefault时才能正常工作的介绍到此结束,谢谢您的阅读,有关Caused by: java.lang.ClassNotFoundException: kafka.DefaultSource、Caused by: java.lang.ClassNotFoundException: org.springframework.web.filter.FormContentFilter、Codeforces 1082 C. Multi-Subject Competition-有点意思 (Educational Codeforces Round 55 (Rated for Div...、codeforces 981 C.Useful Decomposition等更多相关知识的信息可以在本站进行查询。

本文标签: