# P3691 妖精大战争 神经网络初窥

https://www.luogu.org/problemnew/show/P3691

https://www.jianshu.com/p/d7189cbd0983?from=groupmessage

AC快乐就VANS了。省赛加油

```#include<bits/stdc++.h>
using namespace std;
double wx, wy, b;
double dx, dy, db;
double learnrate = 0.3;
double dset[100000][3];
void init(){
wx = 0.5;
wy = 0.5;
b = 1.0;
}

void train(double x, double y, int t){
double res;
res = wx * x + wy * y + b;
res = t - tanh(res);
dx += learnrate * (res * x);
dy += learnrate * (res * y);
db += learnrate * (res);

}
int main(){
int n, m, p;
double x, y;
init();
int t;
cin >> n >> m >> k;
for (int i = 0; i < n; i++)
cin >> dset[i][0] >> dset[i][1] >> dset[i][2];
for (int k = 0; k < 1000; k++){
dx = 0;
dy = 0;
db = 0;
for (int i = 0; i < n; i++){
train(dset[i][0], dset[i][1], dset[i][2]);
}
wx += dx;
wy += dy;
b += db;

//cout << wx << "," << wy << ":" << b << endl;
//system("pause");
//cout << wx << "," << wy << ":" << b << endl;
}
for (int i = 0; i < m; i++){
cin >> x >> y;
double ge;
ge = tanh(wx * x + wy * y + b);
//cout << ge <<  endl;
if (ge <= 0) cout << "-1" << endl;
if (ge > 0) cout << "1" << endl;
}

```

## 3 条评论

1. 居然研究这个。

• b-a

其实很简单的，就一条神经元，而且还没有用到反向传播算法。。。

2. 非技术的路过。