目录


描述

【问题背景】

人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别、函数逼近及贷款风险评估等诸多领域有广泛的应用。对神经网络的研究一直是当今的热门方向,兰兰同学在自学了一本神经网络的入门书籍后,提出了一个简化模型,他希望你能帮助他用程序检验这个神经网络模型的实用性。

【问题描述】

在兰兰的模型中,神经网络就是一张有向图,图中的节点称为神经元,而且两个神经

元之间至多有一条边相连,下图是一个神经元的例子:

人工智能神经网络 论文 人工智能神经网络例题_TOJ

神经元〔编号为1)

图中,X1―X3是信息输入渠道,Y1-Y2是信息输出渠道,C1表示神经元目前的状态,

Ui是阈值,可视为神经元的一个内在参数。

神经元按一定的顺序排列,构成整个神经网络。在兰兰的模型之中,神经网络中的神

经无分为几层;称为输入层、输出层,和若干个中间层。每层神经元只向下一层的神经元

输出信息,只从上一层神经元接受信息。下图是一个简单的三层神经网络的例子。

人工智能神经网络 论文 人工智能神经网络例题_TOJ_02

兰兰规定,Ci服从公式:(其中n是网络中所有神经元的数目)

人工智能神经网络 论文 人工智能神经网络例题_TOJ_03

公式中的Wji(可能为负值)表示连接j号神经元和 i号神经元的边的权值。当 Ci大于0时,该神经元处于兴奋状态,否则就处于平静状态。当神经元处于兴奋状态时,下一秒

它会向其他神经元传送信号,信号的强度为Ci。

如此.在输入层神经元被激发之后,整个网络系统就在信息传输的推动下进行运作。

现在,给定一个神经网络,及当前输入层神经元的状态(Ci),要求你的程序运算出最后网

络输出层的状态。

输入

第一行是两个整数n(1≤n≤200)和p。接下来n行,每行两个整数,第i+1行是神经元i最初状态和其阈值(Ui),非输入层的神经元开始时状态必然为0。再下面P行,每行由两个整数i,j及一个整数Wij,表示连接神经元i、j的边权值为Wij。

输出

包含若干行,每行有两个整数,分别对应一个神经元的编号,及其最后的状
态,两个整数间以空格分隔。仅输出最后状态大于零的输出层神经元状态,并且按照编号由
小到大顺序输出!
若输出层的神经元最后状态均为 0,则输出 NULL。
输出层神经元定义:神经元无出边。 

样例输入

5 6
1 0
1 0
0 1
0 1
0 1
1 3 1
1 4 1
1 5 1
2 3 1
2 4 1
2 5 1

样例输出

3 1
4 1
5 1

思路

设c [ i ] 为神经元状态,c [ i ] 初始值为0的神经元为输入层神经元。out [ i ] 记录神经元的出度,出度为0的为输出层神经元。输入层神经元加入队列,进行广度优先遍历,

每次遍历节点u ,若c[[ u ]<=0 则跳过当前点,否则更新下一层的c [ i ], c[ i ]+=w [ u ] [ i ]。遍历结束按编号大小输出 神经元状态>0的输出层神经元,无输出则输出“NULL”。

人工智能神经网络 论文 人工智能神经网络例题_人工智能 神经网络 论文_04

人工智能神经网络 论文 人工智能神经网络例题_返回顶部_05

#include<bits/stdc++.h>
using namespace std;
queue<int> q;
int n,p;
int c[205],u[205],w[205][205],vis[205],out[205];
int main(){
      scanf("%d%d",&n,&p);
      for(int i=1;i<=n;i++){
          scanf("%d%d",&c[i],&u[i]);
          if(c[i]>0){
            q.push(i),vis[i]=1;
          }else {
            c[i]-=u[i];
          }
      }
      for(int i=1;i<=p;i++){
         int x,y,z;
         scanf("%d%d%d",&x,&y,&z);
         w[x][y]=z;
         out[x]++;
      }
      while(!q.empty()){
           int u=q.front();
           q.pop();
           if(c[u]<=0)continue;
           for(int i=1;i<=n;i++){
               if(w[u][i]!=0){
                  c[i]+=c[u]*w[u][i];
                  if(!vis[i]){
                    q.push(i);
                    vis[i]=1;
                  }
               }
           }
      }
      int flag=0;
      for(int i=1;i<=n;i++){
        if(out[i]==0&&c[i]>0){
            printf("%d %d\n",i,c[i]);
            flag=1;
        }
      }
      if(!flag)printf("NULL\n");
}

 

描述

x! mod (x+1) = x

zzx和city发现了如上的一个等式,想解方程求出x的值,却发现有许多x的值均满足这个等式,随着x的增加zzx发现阶乘太难算,于是叫city写一个大数模拟,而city沉迷于找规律不可自拔。所以现在zzx想请你帮忙求一下对于一个大数x是否满足这个等式。

输入

输入数据有多组,输入到文件结束为止。

每组包括一个正整数x(x<=1019)。

输出

每次输出占一行,样式为Case i: ans,表示第i组测试数据答案为ans。

ans为yes表示输入的x满足题目的等式,ans为no表示输入的x不满足这个等式。

样例输入 

1
2
99999999976

样例输出

case 1:yes
case 2:yes
case 3:yes

思路

判断x+1是否为素数

JAVA 大数类:

人工智能神经网络 论文 人工智能神经网络例题_人工智能 神经网络 论文_04

人工智能神经网络 论文 人工智能神经网络例题_返回顶部_05

import java.math.BigInteger;
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
              Scanner Input =new Scanner(System.in);
              int cas=0;
              while (Input.hasNext()) 
              {
                BigInteger n=Input.nextBigInteger();
                n=n.add(BigInteger.valueOf(1));
                ++cas;
                if(n.isProbablePrime(1))
                 System.out.println("case "+cas+":yes");
                else 
                 System.out.println("case "+cas+":no");    
            }
    }
}

View Code

描述

抹布学长不仅喜欢扑克,还喜欢中国象棋,现在他准备教小朋友下象棋。

棋盘由8*8共64个格子组成,中间是“楚河汉界”,其中的落子点在交叉处,10行9列共90个。

人工智能神经网络 论文 人工智能神经网络例题_i++_08

其中“马”以日字形规则移动,如马当前的坐标位置是(3, 4),它的下一步可以到达(2, 6), (4, 6), (5, 5), (5, 3), (4, 2), (2, 2), (1, 3), (1, 5)共八个位置(如图所示)。

现在给定起点位置和终点位置,问马能不能从起点一步到达终点。

输入

输入数据由一行4个元素组成,分别是sx,sy,ex,ey,表示起点(sx, sy)和终点(ex, ey),起点和终点一定位于棋盘上。

输出

如果能一步即可到达则输出Yes,否则输出No

样例输入

 3 4 5 5

样例输出

 Yes

提示

样例中从(3, 4)能一步到达(5, 5)。

思路

枚举起点(sx, sy)的八种终点,与点(ex,ey)进行比较。

人工智能神经网络 论文 人工智能神经网络例题_人工智能 神经网络 论文_04

人工智能神经网络 论文 人工智能神经网络例题_返回顶部_05

#include<bits/stdc++.h>
using namespace std;
int dtx[]={1,2,-1,-2,1,2,-1,-2};
int dty[]={2,1,-2,-1,-2,-1,2,1};
int x,y,a,b;
int main(){
     scanf("%d%d%d%d",&x,&y,&a,&b);
     int flag=0;
     for(int i=0;i<8;i++){
        if(x+dtx[i]==a&&y+dty[i]==b)flag=1;
     }
     if(flag)printf("Yes\n");
     else printf("No\n");
}

描述

小Q被邪恶的大魔王困在了迷宫里,love8909决定去解救她。迷宫里面有一些陷阱,一旦走到陷阱里,就会被困身亡:(,迷宫里还有一些古老的传送阵,一旦走到传送阵上,会强制被传送到传送阵的另一头。

现在请你帮助love8909算一算,他至少需要走多少步才能解救到小Q? (上下左右四个方向走,同一个传送门可以多次使用)

输入

第一行为一个整数T,表示测试数据组数。每组测试数据第一行为两个整数N,M,(1 <= N, M <= 50)表示迷宫的长和宽。接下来有N行,每行M个字符,是迷宫的具体描述。
'.'表示安全的位置,'#'表示陷阱,
'Q'表示小Q的位置,'L'表示love8909所在位置,
数据保证love8909只有一个,数据也保证小Q只有一个。小写字母'a'-'z'表示分别表示不同的传送阵,数据保证传送阵两两配对。

输出

每组数据输出一行,解救小Q所需的最少步数,如果无论如何都无法救小Q,输出-1。

样例输入

2
5 5
....L
.###.
b#b#a
##.##
...Qa
5 5
....L
.###.
.#.#.
##.##
...Q.

样例输出

3
-1

思路

搜索题

人工智能神经网络 论文 人工智能神经网络例题_人工智能 神经网络 论文_04

人工智能神经网络 论文 人工智能神经网络例题_返回顶部_05

#include<bits/stdc++.h>
using namespace std;
int t,n,m;
char s[55][55];
struct point{
   int x,y,step;
}L,Q;
vector<point> v[30];
bool vis[55][55];
int dtx[]={1,-1,0,0};
int dty[]={0,0,-1,1};
bool check(point d){
     if(d.x>=0&&d.x<n&&d.y>=0&&d.y<m)return 1;
     return 0;
}
int bfs(){
    queue<point> q;
    L.step=0;
    q.push(L);
    vis[L.x][L.y]=1;
    while(!q.empty()){
        point u=q.front();
        q.pop();
        if(s[u.x][u.y]=='Q')return u.step;
        for(int i=0;i<4;i++){
            point o;
            o.x=u.x+dtx[i];
            o.y=u.y+dty[i];
            o.step=u.step+1;
            if(!check(o))continue;
            if(vis[o.x][o.y]==1)continue;
            if(s[o.x][o.y]=='#')continue;
            if(s[o.x][o.y]=='.'){
                vis[o.x][o.y]=1;
                q.push(o);
            }else {
                char ch=s[o.x][o.y];
                if(ch=='Q')return o.step;
                vis[o.x][o.y]=1;
                if(v[ch-'a'][0].x==o.x&&v[ch-'a'][0].y==o.y){
                    o.x=v[ch-'a'][1].x;
                    o.y=v[ch-'a'][1].y;
                }else {
                    o.x=v[ch-'a'][0].x;
                    o.y=v[ch-'a'][0].y;
                }
                q.push(o);
            }
        }
    }
    return -1;
}
int main(){
     scanf("%d",&t);
     while(t--){
         scanf("%d%d",&n,&m);
         memset(vis,0,sizeof(vis));
         for(int i=0;i<30;i++)v[i].clear();
         for(int i=0;i<n;i++){
             scanf("%s",s[i]);
         }
         for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(s[i][j]=='L')L.x=i,L.y=j;
                else if(s[i][j]=='Q')Q.x=i,Q.y=j;
                else if(isalpha(s[i][j]))
                v[s[i][j]-'a'].push_back((point){i,j,0});
            }
         }
         printf("%d\n",bfs());
     }
}

描述

Joe is a skilled programmer. The management of the highway police division wants to control the traffic on the highway, and hired him to solve the following problem. There are some fixed control points on the highway. The highway police division wants to place specialized devices to record information from all the control points. Such a device is very expensive and unfortunately can cover an interval of only one meter (including the left endpoint and excluding the right endpoint). The management wants to place the minimum number of devices to cover all the control points. Joe must find an efficient solution.

输入

The program input is from a text file. Each data set in the file stands for a particular configuration of control points. A data set starts with the number n (n <= 100000) – the number of control points, followed by the real values in ascending order describing the coordinates of the control points (the highway is considered a real line). The coordinates are expressed in meters. White spaces can occur freely in the input. The input data terminate with an end of file.

输出

For each set of data the program has to print the minimum number of devices needed to cover all the control points to the standard output.

样例输入

2
3.56 4
3
1 2 2.9

样例输出

1
2

题意

给定n个点,可以用多个宽度为1的区间(左闭右开)对这些点进行覆盖,求最少的区间数覆盖所有点。

思路

对n个点由小到大排序,再遍历,若当前的被区间覆盖则跳过,否则以当前点为起点建立新的区间,区间数量+1。 

人工智能神经网络 论文 人工智能神经网络例题_人工智能 神经网络 论文_04

人工智能神经网络 论文 人工智能神经网络例题_返回顶部_05

#include<bits/stdc++.h>
using namespace std;
double a[100005];
int main(){
      int n;
      while(~scanf("%d",&n)){
           if(n==0){
            printf("0\n");
            continue;
           }
           int num=1;
           for(int i=1;i<=n;i++){
              double x;
              scanf("%lf",&a[i]);
           }
           sort(a+1,a+n+1);
           double z=a[1];
           for(int i=1;i<=n;i++){
             if(a[i]<z+1)continue;
             else z=a[i],num++;
           }
           printf("%d\n",num);
      }
}

描述

Triangle is the most stable graphics,so zzd likes to collect it.He wants to collect every different triangles and put them on the wall.In order to make triangles,zzd finds many sticks with different length.Can you tell him how many triangles he can make?

输入

The first line of each test case contains the number of sticks 0 ≤ N ≤ 2500.

The second line contains the elements of sequence - N integers in the range from 0 to 10000 each, separated by spaces.

The input is terminated by a set starting with N = 0. This set should not be processed.

输出

Output must contain a single integer - the number of the triangles zzd could make.

样例输入

3
3 4 5
6
1 2 3 4 5 6
0

样例输出

Case 1: 1
Case 2: 7

题意

给定n条边,问这些边能组成多少个不同的三角形

思路

将n条边按长度排序,枚举三角形的两条边,边 i(枚举 n-1 ~ 0),边 j(枚举 i-1~0),最后二分查找

在 范围 0 ~j-1 的边中 有多少边长大于 边 i 与边 j 之差 x。

人工智能神经网络 论文 人工智能神经网络例题_返回顶部_05

#include<bits/stdc++.h>
using namespace std;
int a[3000];
int main(){
      int n,cas=0;
      while(~scanf("%d",&n),n){
           for(int i=0;i<n;i++){
               scanf("%d",&a[i]);
           }

           int sum=0;
           sort(a,a+n);
           for(int i=n-1;i>=0;i--){
               for(int j=i-1;j>=0;j--){
                  int x=a[i]-a[j];
                  int pos=upper_bound(a,a+j,x)-a;
                  if(pos>=j)break;
                  sum+=j-pos;
               }
           }
           printf("Case %d: %d\n",++cas,sum);
      }
}

描述

Farmer John's N (1 <= N <= 10,000) cows (conveniently numbered 1..N) graze in a straight line in their pasture whose length is L+1 (N <= L <= 100,000) meters. Every morning, they place themselves at various unique integer locations along that line. FJ has observed that the cows produce more milk when the distance to the other grazing cows is maximized.

Always the enterprising farmer, FJ wants to maximize the distance between each and every pair of neighboring cows by moving the cows to the right or left, but always with integer inter-cow spacing and never changing their order on the line. He spends 1 minute to move a cow 1 meter. When he's finished, he knows that the distances between every adjacent pair of cows will be one of two integers: D or D+1.

Help FJ to calculate minimum time he needs to arrange the positions of the cows.

输入

Line 1: Two space-separated integers, N and L

Lines 2..N+1: Line i+1 describes cow i with a single integer (range 0..L) representing the position of a cow; 0 is the left-most position. The list is sorted by position with the smallest position value first.

输出

Line 1: A single line with minimum time FJ needs to arrange the positions of the cows.

样例输入

5 10
0
1
4
9
10

样例输出

3

提示

Explanation of the sample:

The cows are arranged like this at the start:

1 2 - - 3 - - - - 4 5

The cows end up arranged like this:

1 - 2 - 3 - - 4 - - 5

题意

有N个点在长度为L直线上(点的范围[0,L]),每个点的相对顺序不变,使相邻点的距离均为 d 或 d+1,将一个点移动一个单位距离的花费为1,求将序列按照上述要求调整的最小花费。

思路

第一个点一定调整在0位置上,最后一个点一定调整在L 位置上。距离d 应为 L/(N-1)。low [ i ]表示i点的下边界,up [ i ]表示i点的上边界,即 i 点能够调整到区间 [ low[ i ],up[ i ] ]上;

 令dp[ i ][ j ]表示将 第i个点调整到 j位置上的最小花费.  dp[ i ][ j ]={ dp [ i -1][ k ]+abs(j - num[ i ])}    

代码中以滚动数组来节省空间

人工智能神经网络 论文 人工智能神经网络例题_人工智能 神经网络 论文_04

人工智能神经网络 论文 人工智能神经网络例题_返回顶部_05

#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
int n,l,up[10005],low[10005],dp[100005],num[10005];
int main(){
    scanf("%d%d",&n,&l);
    low[1]=0;
    up[1]=0;
    up[n]=l;
    low[n]=l;
    if(n==1){
        printf("0\n");
        return 0;
    }
    for(int i=1;i<=n;i++){
        scanf("%d",&num[i]);
    }
    int d=l/(n-1);
    for(int i=2;i<n;i++){
        low[i]=max(d*(i-1),l-(d+1)*(n-i));
        if(low[i]<0)low[i]=0;
        up[i]=min((d+1)*(i-1),l-(d*(n-i)));
        if(up[i]>l)up[i]=l;
    }
    memset(dp,inf,sizeof(dp));
    dp[0]=num[1];
    for(int i=2;i<=n;i++){
        for(int j=up[i];j>=low[i];j--){
            int k=j-d;
            dp[j]=inf;
            if(k<=up[i-1]&&k>=low[i-1])
            dp[j]=min(dp[j],dp[k]+abs(j-num[i]));
            k--;
            if(k<=up[i-1]&&k>=low[i-1])
            dp[j]=min(dp[j],dp[k]+abs(j-num[i]));
        }
    }
    printf("%d\n",dp[l]);
}


描述

Farmer John is gathering the cows. His farm contains a network of N (1 <= N <= 100,000) fields conveniently numbered 1..N and connected by N-1 unidirectional paths that eventually lead to field 1. The fields and paths form a tree.

Each field i > 1 has a single one-way, exiting path to field P_i, and currently contains C_i cows (1 <= C_i <= 1,000,000,000). In each time unit, no more than M_i (0 <= M_i <= 1,000,000,000) cows can travel from field i to field P_i (1 <= P_i <= N) (i.e., only M_i cows can traverse the path).

Farmer John wants all the cows to congregate in field 1 (which has no limit on the number of cows it may have). Rules are as follows:

    * Time is considered in discrete units.

    * Any given cow might traverse multiple paths in the same time unit. However, no more than M_i total cows can leave field i (i.e., traverse its exit path) in the same time unit.

    * Cows never move *away* from field #1.

In other words, every time step, each cow has the choice either to

    a) stay in its current field

    b) move through one or more fields toward field #1, as long
       as the bottleneck constraints for each path are not violated

Farmer John wants to know how many cows can arrive in field 1 by certain times. In particular, he has a list of K (1 <= K <= 10,000)
times T_i (1 <= T_i <= 1,000,000,000), and he wants to know, for each T_i in the list, the maximum number of cows that can arrive
at field 1 by T_i if scheduled to optimize this quantity.

Consider an example where the tree is a straight line, and the T_i list contains only T_1=5, and cows are distibuted as shown:

Locn:      1---2---3---4      <-- Pasture ID numbers
C_i:       0   1   12  12     <-- Current number of cows
M_i:           5   8   3      <-- Limits on path traversal; field
                                  1 has no limit since it has no exit

The solution is as follows; the goal is to move cows to field 1:

Tree:      1---2---3---4
t=0        0   1   12  12     <-- Initial state
t=1        5   4   7   9      <-- field 1 has cows from field 2 and 3
t=2        10  7   2   6
t=3        15  7   0   3
t=4        20  5   0   0
t=5        25  0   0   0

Thus, the answer is 25: all 25 cows can arrive at field 1 by time t=5.

输入

* Line 1: Two space-separated integers: N and K

* Lines 2..N: Line i (not i+1) describes field i with three space-separated integers: P_i, C_i, and M_i

* Lines N+1..N+K: Line N+i contains a single integer: T_i

输出

* Lines 1..K: Line i contains a single integer that is the maximum number of cows that can arrive at field 1 by time T_i.

样例输入

4 1
1 1 5
2 12 7
3 12 3
5

样例输出

25

题意

有一个N节点的树(1为根)和K次询问,2~N节点各自有一个父亲节点 fa[ i ],点上有num[ i ]头奶牛 ,i点与父亲节点fa[ i ]有一条最大流量为 flow[ i ]的路径。根节点1上初始为0头牛。

现在每过一秒,每个点都可以选择将点上的牛保持在原地,或者向fa[i]节点以及距离根节点1更近的祖先节点运输奶牛(只要保持路径上运输量不超过flow[ i ]) 。现有K次询问,每次询问有

一个时间 t ,求在 t 秒时间在根节点1上能拥有奶牛的最大数量。

思路

让每条路径都保持满流状态,用poss[ i ]来表示每秒i节点奶牛的数量变化,poss[ i ] = flow [ i ] - {flow[ j ] } (j 表示所有 i 的子节点) ,这样当poss[ i ]为正数即表示i节点上每秒钟会减少多少头牛,

为负数表示i节点上每秒钟会增加多少头牛。poss[ i ]为正时,i节点持有的奶牛数 会在num[ i ] / poss[ i ]后 变为0,这是可以将i 与其 祖先节点t1合并为一点(并查集) 形成一个新点 poss[ t1 ] +=poss[ i ] ,

num[ t1 ] += num[ i ] ,以及新的时间 num[ t1 ] / poss[ t1 ]。离线处理K次查询,用优先队列维护时间,当查询时间t <=q.top().t  : ans=num[ 1 ]+ poss[ i ] * t; 

人工智能神经网络 论文 人工智能神经网络例题_人工智能 神经网络 论文_04

人工智能神经网络 论文 人工智能神经网络例题_返回顶部_05

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long LL;
int n,k,fa[N],f[N];
LL num[N],flow[N],poss[N];
struct node{
   int i;
   LL t,ans;
}qr[10005];
struct point{
   int i;
   LL t;
   bool operator<(const point &b)const{
        return t>b.t;
   }
};
int cmp(node x,node y){
     return x.t<y.t;
}
int cmp1(node x,node y){
     return x.i<y.i;
}
priority_queue<point> q;
int find(int x){
     return f[x]==x?x:find(f[x]);
}
int main(){
     scanf("%d%d",&n,&k);
     for(int i=1;i<=n;i++)f[i]=i;
     for(int i=2;i<=n;i++){
         scanf("%d%lld%lld",&fa[i],&num[i],&flow[i]);
         poss[fa[i]]-=flow[i];
         poss[i]+=flow[i];
     }
     for(int i=1;i<=k;i++){
        scanf("%lld",&qr[i].t);
        qr[i].i=i;
     }
     sort(qr+1,qr+k+1,cmp);
     for(int i=2;i<=n;i++){
         if(poss[i]>0)
         q.push((point){i,num[i]/poss[i]});
     }
     int pos=1;
     while(!q.empty()&&pos<=k){
         point e=q.top();
         while(qr[pos].t<=e.t&&pos<=k){
            qr[pos].ans=num[1]-poss[1]*qr[pos].t;
            pos++;
         }
          q.pop();
         if(f[e.i]!=e.i){
            continue;
         }
         int t1=find(fa[e.i]);
         num[t1]+=num[e.i];
         poss[t1]+=poss[e.i];
         f[e.i]=t1;
         if(poss[t1]>0)q.push((point){t1,num[t1]/poss[t1]});
     }
     sort(qr+1,qr+k+1,cmp1);
     for(int i=1;i<=k;i++){
         printf("%lld\n",qr[i].ans);
     }
}

描述

A great deal in today's mobile communication depends on having a direct view to a satellite. For communication providers it is therefore crucial to know where their services are available.
You are to identify locations which have a direct view to a particular satellite, i.e. this satellite must be above the horizon. To make things easier you may assume that the earth is a perfect sphere with a radius of 6378 km (mountains will be added next year...). The satellite is a pointlike object above the earth's surface.

输入

The input file consists of several test cases. For each test case the first line contains the number of locations n to be checked followed by the position of the satellite: its latitude, its longitude (both in degrees) and its height (in km) above the earth's surface.
Each of the following n lines contains a location on the earth's surface: the location's label (a sequence of less than 60 printable ASCII characters containing no whitespace characters) followed by its latitude and longitude (both in degrees).
Input is terminated by n=0.

输出

For each test case output the number of the test case as formatted in the sample output. Then, output the locations from where the satellite is visible by printing the corresponding labels on separate lines in the same order as they appear in the input file.
Output a blank line after each test case.

样例输入

3 20.0 -60.0 150000000.0
Ulm 48.406 10.002
Jakarta -6.13 106.75
Honolulu 21.32 -157.83
2 48.4 10 0.5
Ulm 48.406 10.002
Honolulu 21.32 -157.83
0 0.0 0.0 0.0

样例输出

Test case 1:
Ulm
Honolulu

Test case 2:
Ulm

题意

有一个经纬度为(lat,lng)离地距离height的卫星,现给出多个位于地表上的点,用经纬度表示(地球被认作一个半径6738千米的球体)

问该点是否在卫星的覆盖范围内。

思路

根据相对的经纬度作一个三维坐标轴,卫星的经度方向作为y轴正半轴,地心为原点,在zoy的平面上,纬度90度作为z轴正半轴,过卫星点作zoy面上圆的两条切线,确定两个切点,两个切点,两点确定一条直线。

将经纬度转换为三维坐标,取(y,z)坐标得到点在zoy面上的投影。当卫星点的纬度大于0时,(y,z)在直线上方(包括在直线上),则该点在卫星覆盖范围内。当卫星点的纬度小于0时,(y,z)在直线下方

(包括在直线上),则该点在卫星覆盖范围内。

 

人工智能神经网络 论文 人工智能神经网络例题_i++_20

 

人工智能神经网络 论文 人工智能神经网络例题_人工智能 神经网络 论文_04

人工智能神经网络 论文 人工智能神经网络例题_返回顶部_05

#include<bits/stdc++.h>
using namespace std;
int n;
const double R=6378.0;
const double pi=acos(-1.0);
const double esp=1e-8;
struct point{
    double x,y;
}p[2];
double torad(double deg)
{
    return deg/180*pi;
}
double todeg(double deg){
    return deg*180/pi;
}
void get_coordinate(double lat,double lng,double &x,double &y,double &z)
{
    lat = torad(lat);
    lng = torad(lng);
    x = -R*cos(lat)*sin(lng);
    y = R*cos(lat)*cos(lng);
    z = R*sin(lat);
}
double lat,lng,height;
int main(){
      int cas=0;
      while(~scanf("%d%lf%lf%lf",&n,&lat,&lng,&height),n){
           printf("Test case %d:\n",++cas);
           double z=todeg(acos(R/(R+height)));//纬度偏移角
           double angle=torad(z+lat),angle1=torad(lat-z);
           p[0].x=cos(angle)*R,p[0].y=sin(angle)*R;
           p[1].x=cos(angle1)*R,p[1].y=sin(angle1)*R;
           double a,b;
           int flag=0;
           if(abs(p[0].x-p[1].x)<esp)flag=1,a=p[0].x;
           else a=(p[0].y-p[1].y)/(p[0].x-p[1].x),b=p[0].y-a*p[0].x;
           for(int i=1;i<=n;i++){
               char s[105];
               double Lat,Lng;
               scanf("%s%lf%lf",s,&Lat,&Lng);
               Lng=Lng-lng;
               double x,y,z;
               get_coordinate(Lat,Lng,x,y,z);
               if(flag==1){
                   if(y>=a)printf("%s\n",s);
               }else {
                   if(lat>0){
                      if(a*y+b<=z)printf("%s\n",s);
                   }else {
                      if(a*y+b>=z)printf("%s\n",s);
                   }
               }
           }
           printf("\n");
      }
}

描述

NOI2011 在吉林大学开始啦!为了迎接来自全国各地最优秀的信息学选手,吉林大学决定举办两场盛大的 NOI 嘉年华活动,分在两个不同的地点举办。每个嘉年华可能包含很多个活动,而每个活动只能在一个嘉年华中举办。 
现在嘉年华活动的组织者小安一共收到了 n个活动的举办申请,其中第i个活动的起始时间为 Si,活动的持续时间为Ti。这些活动都可以安排到任意一个嘉年华的会场,也可以不安排。

小安通过广泛的调查发现,如果某个时刻,两个嘉年华会场同时有活动在进行(不包括活动的开始瞬间和结束瞬间),那么有的选手就会纠结于到底去哪个会场,从而变得不开心。所以,为了避免这样不开心的事情发生,小安要求不能有两个活动在两个会场同时进行(同一会场内的活动可以任意进行)。 
另外,可以想象,如果某一个嘉年华会场的活动太少,那么这个嘉年华的吸引力就会不足,容易导致场面冷清。所以小安希望通过合理的安排,使得活动相对较少的嘉年华的活动数量最大。 
此外,有一些活动非常有意义,小安希望能举办,他希望知道,如果第i 个活动必须举办(可以安排在两场嘉年华中的任何一个),活动相对较少的嘉年华的活动数量的最大值。

输入

输入的第一行包含一个整数 n,表示申请的活动个数。 
接下来 n 行描述所有活动,其中第 i 行包含两个整数 Si、Ti,表示第 i 个活动从时刻Si开始,持续 Ti的时间。

1≤n≤200,0≤Si≤10^9,1≤Ti≤ 10^9

输出

输出的第一行包含一个整数,表示在没有任何限制的情况下,活动较少的嘉年华的活动数的最大值。 
接下来 n 行每行一个整数,其中第 i 行的整数表示在必须选择第 i 个活动的前提下,活动较少的嘉年华的活动数的最大值。

样例输入

5
8 2
1 5
5 3
3 2
5 3

样例输出

2
2
1
2
2
2

提示

在没有任何限制的情况下,最优安排可以在一个嘉年华安排活动 1, 4,而在另一个嘉年华安排活动 3, 5,活动2不安排。

 

思路

先将时间离散化 ,(len为离散化后的时间长度)

num[i][j]表示在i~j的时间里,有多少项活动

pre[i][j]表示在 1 ~ i 的时间,A地举办 j 次活动时B地举办活动的最大次数

nex[i][j]表示在 i ~ len 的时间,A地举办  j 次活动时B地举办活动的最大次数

val[i][j]表示在选中i~j的时间内活动的情况下,A地活动次数与B地活动次数较小者的最大值

① num[ i ][ j ] 枚举n个时间段,枚举i <= 时间段左端点 ,枚举j >= 时间段右端点 

②pre[i][j]=max{ max{ pre[k][j]+num[k][i],pre[k][j-num[k][i]] } };(1<=k<i)

③nex[i][j]=max{ max{ nex[k][j]+num[k][i],nex[k][j-num[k][i]] } };( i<k<=len)

④val[i][j]=max(val[i][j],min(x+y,pre[i][x]+num[i][j]+nex[j][y])); (x ∈[ 0,num[ 1 ][ i ] ])(y ∈[ 0,num[ j ][ len ] ])

因为 x递增时 y应该递减,当x ,y同时递增时 B地的活动会越来越少   

第一问答案 res=max(res,min(i,pre[len][i]))  i∈[ 0,n ]

第二问答案 res=max(res,val[ i ][ j ]) i∈[ 1,l ] j ∈[ r,len ]  ( l为时间段左端点,r为时间段右端点)

人工智能神经网络 论文 人工智能神经网络例题_人工智能 神经网络 论文_04

人工智能神经网络 论文 人工智能神经网络例题_返回顶部_05

#include<bits/stdc++.h>
using namespace std;
const int N=405;
struct point{
    int x,y;
}e[N];
int f[N];
int num[N][N];//num[i][j]表示在i~j的时间里,有多少项活动
int pre[N][N];//pre[i][j]表示在1~i的时间,A地举办j项活动时B地举办活动的最大次数
int nex[N][N];//nex[i][j]表示在i~len的时间,A地举办j项活动时B地举办活动的最大次数
int val[N][N];//val[i][j]表示在选中i~j的时间内活动的情况下,A地活动次数与B地活动次数较小者的最大值
int main(){
      int n;
      int sz=0;
      scanf("%d",&n);
      for(int i=1;i<=n;i++){
         int a,b;
         scanf("%d%d",&a,&b);
         e[i]=(point){a,a+b};
         f[++sz]=a;
         f[++sz]=a+b;
      }
      sort(f+1,f+sz+1);
      int len=unique(f+1,f+sz+1)-f-1;
      for(int i=1;i<=n;i++){
         e[i].x=lower_bound(f+1,f+len+1,e[i].x)-f;
         e[i].y=lower_bound(f+1,f+len+1,e[i].y)-f;
      }
      for(int i=1;i<=n;i++){
          for(int j=1;j<=e[i].x;j++){
                for(int z=e[i].y;z<=len;z++){
                    num[j][z]++;
                }
          }
      }
      for(int i=1;i<=len;i++){
        for(int j=1;j<=n;j++){
            pre[i][j]=nex[i][j]=-0x3f3f3f3f;
        }
      }
      for(int i=1;i<=len;i++){
         for(int j=0;j<=n;j++){
             for(int z=1;z<i;z++){
                    pre[i][j]=max(pre[z][j]+num[z][i],pre[i][j]);
                 if(j>=num[z][i]){
                    pre[i][j]=max(pre[z][j-num[z][i]],pre[i][j]);
                 }
             }
         }
      }
      nex[len][0]=0;
      for(int i=len;i>=1;i--){
         for(int j=0;j<=n;j++){
              for(int z=i+1;z<=len;z++){
                 nex[i][j]=max(nex[z][j]+num[i][z],nex[i][j]);
                 if(j>=num[z][i]){
                    nex[i][j]=max(nex[z][j-num[i][z]],nex[i][j]);
                 }
              }
         }
      }
      for(int i=1;i<len;i++){
           for(int j=i+1;j<=len;j++){
             for(int x=0,y=num[j][len];x<=num[1][i];x++){
                 while(y){
                    int v1=min(x+y,pre[i][x]+num[i][j]+nex[j][y]);
                    int v2=min(x+y-1,pre[i][x]+num[i][j]+nex[j][y-1]);
                    if(v2>=v1)y--;
                    else break;
                 }
                val[i][j]=max(val[i][j],min(x+y,pre[i][x]+num[i][j]+nex[j][y]));
             }
           }
      }
      int res=0;
      for(int i=0;i<=n;i++){
          res=max(res,min(i,pre[len][i]));
      }
      printf("%d\n",res);
      for(int k=1;k<=n;k++){
           res=0;
           for(int i=1;i<=e[k].x;i++){
               for(int j=e[k].y;j<=len;j++){
                  res=max(res,val[i][j]);
               }
           }
           printf("%d\n",res);
      }
}