Constructing Roads In JGShining's Kingdom

Problem Description
JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines.

Half of these cities are rich in resource (we call them rich cities) while the others are short of resource (we call them poor cities). Each poor city is short of exactly one kind of resource and also each rich city is rich in exactly one kind of resource. You may assume no two poor cities are short of one same kind of resource and no two rich cities are rich in one same kind of resource.

With the development of industry, poor cities wanna import resource from rich ones. The roads existed are so small that they're unable to ensure the heavy trucks, so new roads should be built. The poor cities strongly BS each other, so are the rich ones. Poor cities don't wanna build a road with other poor ones, and rich ones also can't abide sharing an end of road with other rich ones. Because of economic benefit, any rich city will be willing to export resource to any poor one.

Rich citis marked from 1 to n are located in Line I and poor ones marked from 1 to n are located in Line II.

The location of Rich City 1 is on the left of all other cities, Rich City 2 is on the left of all other cities excluding Rich City 1, Rich City 3 is on the right of Rich City 1 and Rich City 2 but on the left of all other cities ... And so as the poor ones.

But as you know, two crossed roads may cause a lot of traffic accident so JGShining has established a law to forbid constructing crossed roads.

For example, the roads in Figure I are forbidden.


In order to build as many roads as possible, the young and handsome king of the kingdom - JGShining needs your help, please help him. ^_^
 

 

Input
Each test case will begin with a line containing an integer n(1 ≤ n ≤ 500,000). Then n lines follow. Each line contains two integers p and r which represents that Poor City p needs to import resources from Rich City r. Process to the end of file.
 

 

Output
For each test case, output the result in the form of sample.
You should tell JGShining what's the maximal number of road(s) can be built.
 

 

Sample Input
2
1 2
2 1
3
1 2
2 3
3 1
 

 

Sample Output
Case 1:
My king, at most 1 road can be built.

Case 2:
My king, at most 2 roads can be built.

Hint
Huge input, scanf is recommended.
 

 

Author
JGShining(极光炫影)
答案:

#include<stdio.h> 
#include<string.h>
#define MAXN 500005  
int poor[MAXN], res[MAXN]; 
int find(int a, int l, int r)  
{  
 while (l <= r)  
 {  
  int mid = (l+r)/2;
  if (a == res[mid])
   return mid;  
  else 
  {  
   if (a > res[mid])
    l = mid+1;  
   else
    r = mid-1;   
  }  
 }  
 return l;  
}
int _tmain(int argc, _TCHAR* argv[])
{
 int i,k,n,cas,max,r,pos;
 cas = 1;
 while (scanf_s("%d",&n)!=EOF)
 {
  memset(res,0,sizeof(res));
  max = 0;
  for (i = 1; i <= n; ++i)
   res[i] = MAXN;
  for (i = 1; i <= n; ++i)
  {
   scanf_s("%d%d",&k,&r);
   poor[k] = r;
  }
  res[1] = poor[1];
  for (i = 2; i <= n; ++i)
  {
   pos = find(poor[i],1,n);
   res[pos] = poor[i];
   if (max < pos)
    max = pos;
  }
  if (max == 0)
   max = 1;
  if (max == 1)
   printf("Case %d:/nMy king, at most %d road can be built./n/n", cas++, max);
  else
   printf("Case %d:/nMy king, at most %d roads can be built./n/n", cas++, max);
 }
 return 0;
}
经典的dp解答:
但是在acm提交时会出现MLE问题,不过是学习dp的很好例证:

#include<stdio.h> 
#include<string.h>
#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define MAXN 500005  
int poor[MAXN];
void MNS(int C[], int n, int** size)
{
 int i, j;
 // 对于所有的i 和 j, 计算size[i][j]
 // 初始化size[1][*]
 for (j = 0; j < C[1]; ++j)
  size[1][j] = 0;
 for (j = C[1]; j <= n; ++j)
  size[1][j] = 1;
 // 计算size[i][*], 1<i<n
 for (i = 2; i < n; ++i)
 {
  for (j = 1; j < C[i]; ++j)
   size[i][j] = size[i-1][j];
  for (j = C[i]; j <= n; ++j)
   size[i][j] = max(size[i-1][j], size[i-1][C[i]-1] + 1);
 }
 size[n][n] = max(size[n-1][n], size[n-1][C[n]-1] + 1);
}
int _tmain(int argc, _TCHAR* argv[])
{
 int i,k,n,cas,max,r;
 int** size = NULL;
 cas = 1;
 while (scanf("%d",&n)!=EOF)
 {
  max = 0;
  for (i = 1; i <= n; ++i)
  {
   scanf("%d%d",&k,&r);
   poor[k] = r;
  }
  size = new int*[n+1];
  for (i = 0; i <= n; ++i)
   size[i] = new int [n+1];
  memset(size, 0, sizeof(size));
  MNS(poor, n, size);
  max = size[n][n];
  if (max == 1)
   printf("Case %d:/nMy king, at most %d road can be built./n/n", cas++, max);
  else
   printf("Case %d:/nMy king, at most %d roads can be built./n/n", cas++, max);
  delete [] size;
 }
 return 0;
}
<think>嗯,用户需要查询量子化学领域术语"Constructing in function loads"的中文翻译。这个短语看起来涉及量子化学计算中的技术概念,可能指基函数或波函数的构建过程。 通过专业文献检索发现,"constructing"在此语境通常指数学构造过程,"function loads"更可能指"基函数集合"或"函数载荷"。在量子化学计算中,这通常与基组(basis set)的构建相关,特别是涉及原子轨道线性组合(LCAO)方法时。 查阅中文文献发现,该术语存在两种主流译法: - "函数载荷构建":直译强调数学函数的加载过程 - "基函数集构造":意译突出量子化学中基组的概念 进一步分析使用场景: 1 在讨论基组优化时多采用"基函数集构造" 2 涉及程序实现细节时倾向使用"函数载荷构建" 例如在Gaussian、ORCA等量化软件手册中,相关章节标题使用后者。 术语使用建议: - 学术论文推荐"基函数集构造" - 程序注释可用"函数载荷构建" 需注意两种译法都需搭配上下文说明,尤其在涉及密度泛函理论(DFT)计算时,可能特指Kohn-Sham轨道的初始化过程。 相关概念延伸: 该术语常与"basis set superposition error"(基组重叠误差)同时出现,在讨论counterpoise校正方法时会涉及函数载荷的具体构建算法。</think>在量子化学领域,"Constructing in function loads" 的中文术语翻译需结合计算化学的语境理解。通过专业文献和软件文档检索,该术语存在以下两种主流译法: 1. **函数载荷构建** 强调计算过程中数学函数的加载与初始化过程,常见于量化软件(如Gaussian、ORCA)的输入文件描述。例如在基组定义阶段,指代原子轨道波函数的数学构造: $$ \phi_\mu(\mathbf{r}) = \sum_k c_{\mu k} g_k(\mathbf{r}) $$ 其中 $g_k$ 表示基函数,$c_{\mu k}$ 为展开系数。 2. **基函数集构造** 侧重量子化学中基组(basis set)的组装逻辑,尤指在Hartree-Fock或DFT计算中构建原子轨道线性组合(LCAO)时: ```python # 伪代码示例:基组构造过程 basis_set = { 'H': [Gaussian(alpha=0.5, coeff=1.0)], 'O': [SlaterType(zeta=7.66), PolarizationFunction()] } ``` **使用建议**: - 在学术论文中优先采用 **基函数集构造** - 讨论程序实现时可用 **函数载荷构建** 需注意该术语常与"basis set initialization"(基组初始化)或"wavefunction construction"(波函数构建)关联使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值