头像

wuog

退役养老中




离线:6天前


最近来访(903)
用户头像
淼淼_5
用户头像
牛奶草莓小饼干
用户头像
知更_5
用户头像
cklsyw
用户头像
itdef
用户头像
gocomputer
用户头像
社会废人
用户头像
亡灵大军
用户头像
Vertex
用户头像
Fatin
用户头像
天元之弈
用户头像
谁把可乐的名字拿走了
用户头像
上术
用户头像
梦忆晴天
用户头像
xyj1
用户头像
Lena
用户头像
o_42
用户头像
_Agony
用户头像
MudNewBie
用户头像
硫化细菌

新鲜事 原文

wuog
7天前
CSP-J/S初赛监考真的累🥱,希望各位蒙的都对吧!



wuog
2个月前
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 15;
double a[N][N],b[N][N];
int n;
void Gauss(){
    for(int r=1,c=1;r<=n;++r,++c){
        int t=r;
        for(int i=r+1;i<=n;++i)if(fabs(b[i][c])>fabs(b[t][c]))t=i;
        for(int i=c;i<=n+1;++i)swap(b[r][i],b[t][i]);
        for(int i=n+1;i>=c;--i)b[r][i]/=b[r][c];
        for(int i=r+1;i<=n;++i)
            for(int j=n+1;j>=c;--j)
                b[i][j]-=b[r][j]*b[i][c];
    }
        for(int i=n;i>1;--i)
            for(int j=i-1;j>=1;--j){
                b[j][n+1]-=b[i][n+1]*b[j][i];
                b[j][i]=0;
            }

}
int main()
{
    cin>>n;
    for (int i = 0; i <= n;   ++i )
        for (int j = 1; j <= n;  ++j )
            cin>>a[i][j];
    for (int i = 1; i <= n; ++i )
        for (int j = 1; j <= n;  ++j )
            {
                b[i][j]=2*(a[i][j]-a[0][j]);
                b[i][n+1]+=a[i][j]*a[i][j]-a[0][j]*a[0][j];
            }
    Gauss();
    for (int i = 1; i <= n;  ++i )
      printf("%.3lf ",b[i][n+1]);
    return 0;
}


活动打卡代码 AcWing 1310. 数三角形

wuog
2个月前
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
ll C(ll a,ll b){
    return a*(a-1)*(a-2)/6;
}
int main()
{
    cin>>n>>m;
    n++,m++;
    ll res=C(m*n,3)-n*C(m,3)-m*C(n,3);
    n--,m--;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
          res-=2*(n-i+1)*(m-j+1)*(gcd(i,j)-1);
    cout<<res<<endl;
    return 0;
}


活动打卡代码 AcWing 1309. 车的放置

wuog
2个月前
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2010, mod = 100003;
int f[N], inf[N];
// 快速幂
int qmi(int a, int b)
{
    int res = 1;
    while (b)
    {
        if (b & 1)
            res = (LL)res * a % mod;
        b >>= 1;
        a = (LL)a * a % mod;
    }
    return res;
}
// 组合数
int C(int a, int b)
{
    if (a < b)
        return 0;
    return (LL)f[a] * inf[b] % mod * inf[a - b] % mod;
}
// 排列数
int A(int a, int b)
{
    if (a < b)
        return 0;
    return (LL)f[a] * inf[a - b] % mod;
}
int main()
{
    int a, b, c, d, k;
    cin >> a >> b >> c >> d >> k;
    f[0] = inf[0] = 1;
    for (int i = 1; i < N; i++)
    {
        f[i] = (LL)f[i - 1] * i % mod;
        inf[i] = (LL)inf[i - 1] * qmi(i, mod - 2) % mod;
    }
    int res = 0;
    for (int i = 0; i <= b; i++)
        res = (res + (LL)C(b, i) * A(a, i) % mod * C(d, k - i) % mod * A(a + c - i, k - i) % mod) % mod;
    cout << (res % mod + mod) % mod << endl;
    return 0;
}



活动打卡代码 AcWing 1987. 粉刷栅栏

wuog
7个月前

//
// Created by wyl on 2022/2/4.
//

#include<bits/stdc++.h>

using namespace std;
map<int, int> s;
int n, start=0;

int main() {
    cin.sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a, l, r;
        char c;
        cin >> a >> c;
        if (c == 'L') {
            s[start] --;
            start -= a;
            s[start] ++;
        } else {
            s[start] ++;
            start += a;
            s[start] --;
        }

    }
    int res = 0, sumn = 0, last;
    for (auto a: s) {
        if (sumn > 1) {
            res += a.first - last;
        }
        sumn += a.second;
        last = a.first;
    }
    cout << res << endl;
}


活动打卡代码 AcWing 1945. 奶牛棒球

wuog
7个月前

//
// Created by wyl on 2022/2/4.
//

#include<bits/stdc++.h>

using namespace std;
const int N = 1010;
int n, a[N];
int ans;
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) { scanf("%d", &a[i]); }
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int t = a[j] -a[i];
            int res = upper_bound(a,a+n,a[j]+2*t)- lower_bound(a,a+n,a[j]+t);
//            cout<<res<<endl;
            ans += res;
        }
    }
    cout<<ans<<endl;
}


活动打卡代码 AcWing 1996. 打乱字母

wuog
7个月前

//
// Created by wyl on 2022/2/4.
//

#include<bits/stdc++.h>

using namespace std;
const int N = 50010;
string a[N], b[N], c[N];
int n;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        a[i] = s;
        std::sort(s.begin(), s.end());
        b[i] = s;
        std::reverse(s.begin(), s.end());
        c[i] = s;
    }
    sort(b + 1, b + n + 1);
    sort(c + 1, c + n + 1);
    for (int i = 1; i <= n; i++) {
        string s = a[i];std::sort(s.begin(), s.end());
        string s1 = s;
        cout<<lower_bound(c+1,c+n+1,s)-c<<" ";
        std::reverse(s.begin(), s.end());
        string s2 = s;
        if(!(s1==s2))
            cout<<lower_bound(b+1,b+n+1,s)-b-1<<endl;
        else{
            cout<<lower_bound(b+1,b+n+1,s)-b<<endl;
        }
    }
}


活动打卡代码 AcWing 2005. 马蹄铁

wuog
7个月前

//
// Created by wyl on 2022/2/4.
//

#include<bits/stdc++.h>

using namespace std;
const int N = 10;
int turn[4][2] = {{-1, 0},
                  {1,  0},
                  {0,  -1},
                  {0,  1}};
char M[N][N];
bool used[N][N];
int n, res = 0;

void dfs(int x, int y, int l, int r) {
//    cout<<x<<" "<<y<<" "<<l<<" "<<r<<endl;
    if (l == r) { res=max(res,2*l); return;}
    for (int i = 0; i < 4; i++) {
        int tx = x + turn[i][0], ty = y + turn[i][1];
        if (tx >= 1 && tx <= n && ty >= 1 && ty <= n && used[tx][ty] == false) {
            if(r>0&&M[tx][ty]=='(')continue;
            used[tx][ty]=true;
            if(M[tx][ty]=='(')dfs(tx,ty,l+1,r);
            else dfs(tx,ty,l,r+1);
            used[tx][ty]= false;
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%s", M[i] + 1);
    }
    if(M[1][1]=='('){
        used[1][1] = true;
        dfs(1, 1, 1, 0);
    }
    printf("%d",res);
}


活动打卡代码 AcWing 2014. 岛

wuog
7个月前
//这里填你的代码^^
//注意代码要放在两组三个点之间,才可以正确显示代码高亮哦~

//
// Created by wyl on 2022/2/4.
//

#include<bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10;
map<int, int> s;
int a[N], n;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        if(a[i]>a[i-1]){
            s[a[i-1]]++,s[a[i]]--;
        }
    }
    int res = 0, sumn = 0;
    for(auto t:s){
        sumn+=t.second;
        res = max(sumn,res);
    }
    printf("%d",res);
}


活动打卡代码 AcWing 2019. 拖拉机

wuog
7个月前

//
// Created by wyl on 2022/2/2.
//

#include<bits/stdc++.h>

using namespace std;
typedef pair<int, int> PII;
const int N = 1020;
int turn[4][2] = {{-1, 0},
                  {1,  0},
                  {0,  1},
                  {0,  -1}};

int M[N][N], used[N][N], d[N][N];
int n, sx, sy;
deque<PII> q;

int bfs() {
    q.push_back({sx, sy});
    memset(d, 0x3f, sizeof d);
    d[sx][sy] = 0;
    while (q.size()) {
        auto t = q.front();q.pop_front();
        int x = t.first, y = t.second;
        if (used[x][y])continue;
        used[x][y] = true;
        for (int i = 0; i < 4; i++) {
            int tx = x + turn[i][0], ty = y + turn[i][1];
            if (tx >= 0 && tx < N && ty >= 0 && ty < N) {
                int w = M[tx][ty];
                if (d[x][y] + w < d[tx][ty]) {
                    d[tx][ty] = d[x][y] + w;
                    if (w == 0)q.push_front({tx, ty});
                    else q.push_back({tx, ty});
                }
            }
        }
    }
    return d[0][0];
}

int main() {
    scanf("%d%d%d", &n, &sx, &sy);
    for (int i = 0; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        M[a][b] = 1;
    }
    printf("%d",bfs());
}