2022年4月14日-1

1384

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> PII;
//配对集合。
vector<PII> S;

int a[10010],b[10010];
int main()
{
    std::ios::sync_with_stdio(false);
    int n,m;
    cin >> n >>m;
    if(n == 1) {
        cout << 0 << endl;
        return 0;
    }
    //暴力 
    for(int i = 1;i <= n;i ++) cin >> a[i];
    for(int i = 1;i <= n;i ++) 
    {
        for(int j = 1;j <= n;j ++)
        if(a[i] > a[j]) b[i] ++; 
    }
    //m条邮件 
    while(m --)
    {
        int i,k; cin >> i >> k;
        //k个不喜欢的人 
        while(k --)
        {
            int j; cin >>j;
            if(a[i] < a[j]) S.push_back({j,i});
            else S.push_back({i,j});
        }
    }
    
    //排序
    sort(S.begin(),S.end()); 
    S.erase(unique(S.begin(), S.end()), S.end());
    //枚举减去不喜欢的人的数量。 这些人不喜欢你能量还比你低,或者你不喜欢的人. 
    for(int i = 0;i < S.size();i ++)
    {
        //判断first和second
        int a1 = S[i].first,a2 = S[i].second; 
        if(a[a1] > a[a2]) -- b[a1];
    }
    for(int i = 1;i < n;i++)
    cout << b[i] << " "; 
    cout << b[n] << endl;
}

1385

#include<bits/stdc++.h>
using namespace std;
long long gcd(int x,int y)
{
    return !y?x:gcd(y,x % y);
}
int main()
{
    int T; cin >> T;
    while(T --)
    {
        int a,b,c,d;int ans;
        cin >> a >> b >>c >> d;
        if(a * d + a * c == b * d) cout << 0 << endl;
        else
        {
            long long int up = abs(b * d - a * (d + c));
            long long int down = abs(2 * d * b);
        //    cout << up << down;
            cout << up / gcd(up,down) << '/' << down/gcd(up,down) << endl;
        }
    }
 } 

1386

#include<iostream>
#include<cstring>
#define ll long long
using namespace std;
const int N = 10010;
int a[N],b[N],cnt;
//求C(n,3) 
long long C(int n)
{
    return n * (n - 1) *1LL* (n - 2)/6;
}
void quick_sort(int q[], int l, int r)
{
    //递归的终止情况
    if(l >= r) return;
    //第一步:分成子问题
    int i = l - 1, j = r + 1, x = q[l + r >> 1];
    while(i < j)
    {
        do i++; while(q[i] < x);
        do j--; while(q[j] > x);
        if(i < j) swap(q[i], q[j]);
    }
    //第二步:递归处理子问题
    quick_sort(q, l, j), quick_sort(q, j + 1, r);
    //第三步:子问题合并
}

int main()
{
    ios::sync_with_stdio(false);
    int T; cin >> T;
    while(T --)
    {
        int n;
        cin >> n;
        //b数组存放分好颜色的球,b[i]即第i种颜色的球的个数,这里每个样例前初始化。 
        memset(b,0,sizeof b);
        for(int i = 0;i < n;i ++)
        cin >> a[i];
        //排序方便统计。 
        quick_sort(a,0,n-1);
        int j = 0;int k;
        //遍历所有球,用双指针统计同一种颜色的球个数 
        for(int i = 0;i < n;i ++)
        {    
            if(a[i] == a[i + 1])
            {
                k = i;
                while(a[i] == a[k] && k < n)
                {
                    b[j] ++;
                    k ++;
                }
                i = k - 1; 
            }
            j ++;
        }    
        long long sum = 0;
        for(int i = 0;i < j;i ++)
        {
            if(b[i] >= 3) sum += C(b[i]);
            if(b[i] >= 2) sum+=b[i]*(b[i]-1)*1LL*(n-b[i])/2;
        }
        
        //取两种颜色:在两两组合的颜色里取三个球,双重循环。 
        cout << C(n) - sum << endl;
    }
} 

1403


#include<iostream>
using namespace std;
//求边长 
int find(int x)
{
    int j;
    for(int i = 1;i <= 10;i ++)
    {
        if(x >= (i - 1)*(i - 1)+1 && x <= i * i)
        {
            j = i;
            break;
        }
    }
    return j;
}
int main()
{
    int n;
    while(cin >> n)
    {
        if(n == 0) return 0;
        int a = find(n);
        //菱形最多的'/\' 
        int up = (a * a - a)/2 + a;
        //菱形最多的'\/ 
        int down = (a * a - a)/2;
        //上部分打印 
        int u0 = 0;
        for(int i = 0;i < a;i ++)
        {
            //每行前面的空格 
            for(int j = 0;j + i + 1< a;j ++) printf(" ");    
            //这一行的'/\'                                                                           
            for(int j = 0;j - 1 < i;j ++) 
            {
                u0 ++;
                printf("/\\");    
                if(u0 >= n) break;
            }
            //判断是否满上半部
            if(n == u0 && u0  < up) printf("/\n");
            else printf("\n");    
        }
        //下部分打印
        int cnt = n - down; int u = 0;
        for(int i = 0;i < a;i ++)
        {
            //打印空格 
            for(int j = 0;j < i;j ++) printf(" ");
            //打印'\/'
            for(int j = 0;j + i < a;j ++)
            {
                u ++;
                printf("\\/");    
                if(u >= cnt) break;
            } 
            if(u == cnt) {
                printf("\n");
                break;
            }
            else printf("\n");
        } 
    }
}

1404

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int N = 10010;
LL a[N];
//上部分查询 
int find(int n)
{
    if(n == 1) return 1;
    else
    {
    for(int i = 1;i <= n;i ++)
    if(n > a[i] && n <= a[i + 1])
    {
        return i + 1;
        break;
    }
    }
}
int main()
{
    //创造数列
    a[1] = 1;
    for(int i = 2;i <= N;i ++) 
    a[i] = a[i - 1] + i;
    int T; cin >> T;
    while(T --)
    {
        int s,st,ed; cin >> s >> st >> ed;
        int row1,col1,row2,col2;//行和列和菱形的行 
        //中间值
        int div = (s * s + s)/2;
        if(st > div - s && st <= div) 
        {
            row1 = div - st + 1;
            col1 = s + 1 - row1;
        }
        else if(st > div) //转化成上部分     
        {
            st = s * s + 1 - st;
            col1 = st - a[find(st) - 1];
            row1 = find(st) + 1 - col1;
            col1 = s + 1 - col1;
            row1 = s + 1 - row1;
        }
        else
        {
            col1 = st - a[find(st) - 1];
            row1 = find(st) + 1 - col1;
        }
        //特判:若是在正方形的对角线
        if(ed > div - s && ed <= div) 
        {
            row2 = div - ed + 1;
            col2 = s + 1 - row2; 
        }
        else if(ed > div)
        {
            ed = s * s + 1 - ed;
            col2 = ed - a[find(ed) - 1];
            row2 = find(ed) + 1 - col2;
            col2 = s + 1 - col2;
            row2 = s + 1 - row2;
        }
        else
        {
            col2 = ed - a[find(ed) - 1];
            row2 = find(ed) + 1 - col2;
        }
        //曼哈顿距离
        cout << abs(row1 - row2) + abs(col1 - col2) << '\n'; 
    } 
    return 0;
} 

1406

#include<iostream>
#include<algorithm>
using namespace std;
char a[110],b[110];
int c[26];
int max_char(char s[],int n)
{
    for(int i = 0;i < n;i ++)
    {
        c[s[i] - 'a'] ++;
    }
    sort(c,c+26);
    return c[25];
}
int main()
{
    ios::sync_with_stdio(false);
    int n; cin >> n;
    while(n --)
    {
        int m,k;//m个字母,k个调换次数。
        cin >> m >>k;
        //轮次。
//        k = (k >= m)?k/m:k;
//        cout << k << endl;
        for(int i = 0;i < m;i ++)
        {
            cin >> a[i];
        }
        for(int i = 0;i < m;i ++)
        {
            cin >> b[i];
        }
        //初始化 
        for(int i = 0;i < 26;i++) c[i] = 0;
        int max_1 = max_char(a,m);
        for(int i = 0;i < 26;i++) c[i] = 0;
        int max_2 = max_char(b,m);
//        cout << max_1 <<" " << max_2 << endl;
        if(m == max_1 && k == 1) max_1 = m - 1;
        else max_1 = min(max_1 + k,m);
        if(m == max_2 && k == 1) max_2 = m - 1;
        else max_2 = min(max_2 + k,m);    
//        cout << max_1 <<" " << max_2 << endl;
        if(max_1 > max_2) cout << "Alice" << '\n';
        else if(max_1 < max_2) cout << "Bob" << '\n';
        else cout << "Draw" << '\n';
    }
    return 0;
 } 

1411

#include<iostream>
using namespace std;
int h[100000010];
int main()
{
    ios::sync_with_stdio(false);
    int T; cin >>T;
    while(T --)
    {
        long long n; cin >> n;int j;
        if(n <= 2) cout << 2 << '\n';
        else
        {
            //统计各数码出现次数 
            for(int i = 2;i <= n - 1;i ++)
        {
            for(j = 0;j < i;j ++) h[j] = 0;
            long long u = n;
            while(u)
            {    
                long long int t0 = u % i;
                h[t0] ++;
                u/=i; 
            }
            int maxn = 0;int minn = 1e9;
                for(j = 0;j < i;j ++)
            {
                if(h[j]) {
                    maxn = max(h[j],maxn);
                    minn = min(h[j],minn);
                }
            }
            if(maxn == minn) 
            {
                cout << i << '\n';
                break;
            }
        }
        }
        //每个进制的枚举 
        
    }
}

1412

#include<iostream>
using namespace std;
int a[4][4];
int b1[12],b2[4];
int main()
{
    int T; cin >>T;
    while(T --)
    {
        //存数 
        for(int i = 0;i < 4;i ++)
        for(int j = 0;j < 4;j ++)
        cin >> a[i][j];
        b2[0] = a[1][1];b2[1] = a[1][2];b2[2] = a[2][2];b2[3] = a[2][1];
        int max_1 = 0,max_2 = 0,max_3 = 0;//外圈三个数和内圈两个数 
        int col = 0,row = 0;
        //1求外圈的最大连续三个数加上内圈最大数
            int cnt = 0;
            while(row == 0 && col <= 3)
            {
                b1[cnt ++] = a[row][col];
                col ++;
            }
            col --;row ++;
            while(col == 3 && row <= 3)
            {
                b1[cnt ++] = a[row][col];
                row ++;
            }
            row --;col --;
            while(row == 3 && col >= 0)
            {
                b1[cnt ++] = a[row][col];
                col --;
            }
            col ++;row --;
            while(col == 0 && row >= 0)
            {
                b1[cnt ++] = a[row][col];
                row --;
            }
            max_1 = max(b1[0] + b1[10] + b1[11],b1[11] + b1[0] + b1[1]);
            for(int i = 0;i < 10;i ++)
            max_1 = max(max_1,b1[i] +b1[i + 1] + b1[i + 2]);
            int t = b2[0];
            for(int i = 0;i < 4;i ++) t = max(t,b2[i]);
            max_1 += t;
        //2求外圈的最大连续两个数加上内圈最大连续两个数
            max_2 = b1[0] + b1[11];
            for(int i = 0;i < 11;i ++)
            max_2 = max(max_2,b1[i] +b1[i + 1]);
            t = b2[0] + b2[3];
            for(int i = 0;i < 3;i ++) t = max(t,b2[i] + b2[i + 1]);
            max_2 += t;
        //3求内圈的和
        max_3 = a[1][1] + a[1][2] + a[2][1] + a[2][2];
        max_1 = max(max_1,max_2);
        max_1 = max(max_1,max_3);
        cout << max_1 << '\n';
//        for(int i = 0;i < 12;i ++) cout << b1[i] <<' ';
//        puts("");
//        for(int j = 0;j < 4;j ++) cout << b2[j] << ' ';
    }
return 0;
    
    
     
 } 

1415

#include<iostream>
using namespace std;
typedef long long LL;
const int N = 50010;
int main()
{
    ios::sync_with_stdio(false);
    LL a[N],s[N];
    int T; cin >> T;
    while(T--)
    {
        LL n,p;
        cin >> n >> p;
        for(int  i = 0;i < n;i ++) 
        {
            cin >> a[i];
            s[i + 1] = s[i] + a[i];//s从1下标开始 
        }
        LL sum = 0;
        for(int i = 1;i < n;i ++)
        {
            LL t = s[i];
            LL t0 = s[n] - s[i];
            sum = max(sum,t % p + t0 % p);
        }
        cout << sum << '\n';
    }
    return 0;
}

1425

#include<iostream>
#include<cstring>
using namespace std;
int main(){
    char s[210];
    int m = 0;
    while(~scanf("%s",s) && m < 1000)
    {
        m ++;
        int a[6] = {1,6,5,2,3,4};
        for(int i = 0;i < strlen(s);i ++)
        {
            int u,b,c,d;
            if(s[i] == 'U')
            {
                u = a[0]; b = a[1]; c = a[2]; d = a[3];
                a[0] = c;
                a[1] = d;
                a[2] = b;
                a[3] = u;
            }
            else if(s[i] == 'D')
            {
                u = a[0]; b = a[1]; c = a[2]; d = a[3];
                a[0] = d;
                a[1] = c;
                a[2] = u;
                a[3] = b;
            }
            else if(s[i] == 'L')
            {
                u = a[0]; b = a[1]; c = a[4]; d = a[5];
                a[0] = d;
                a[1] = c;
                a[4] = u;
                a[5] = b;
            }
            else if(s[i] == 'R')
            {
                u = a[0]; b = a[1]; c = a[4]; d = a[5];
                a[0] = c;
                a[1] = d;
                a[4] = b;
                a[5] = u;
            }
            else if(s[i] == 'X')
            {
                u = a[2]; b = a[3]; c= a[4]; d = a[5];
                a[2] = d;
                a[3] =c;
                a[4] =u;
                a[5] = b;
            }
            else if(s[i] == 'Y')
            {
                u = a[2]; b = a[3]; c= a[4]; d = a[5];
                a[2] = c;
                a[3] =d;
                a[4] =b;
                a[5] = u;
            }
        }
        printf("%d\n",a[0]);
    }
}

1426

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int a1[6],a2[6],a3[6];
//结果集合 
vector<int> s;
int main()
{
    ios::sync_with_stdio(false);
    int T; cin >> T;
    int sum1,sum2,sum3,sum4,sum5,sum6;
    while(T --)
    {
        //读入 
        for(int i = 0;i < 6;i ++) cin >> a1[i];
        for(int j = 0;j < 6;j ++) cin >> a2[j];
        for(int k = 0;k < 6;k ++) cin >> a3[k];
        //遍历
        int sum1,sum2,sum3,sum4,sum5,sum6;
        //一种筛子
        for(int i = 0;i < 6;i ++)
        {
            s.push_back(a1[i]); 
            s.push_back(a2[i]); 
            s.push_back(a3[i]); 
        }
        //两个筛子 a1 a2
        for(int i = 0;i < 6;i ++) 
        for(int j = 0;j < 6;j ++)
        {
            sum1 = a1[i]*10 + a2[j];
            sum2 = a2[i]*10 + a1[j];
            s.push_back(sum1);
            s.push_back(sum2);
        } 
        //遍历
        //两个筛子 a1 a3
        for(int i = 0;i < 6;i ++) 
        for(int j = 0;j < 6;j ++)
        {
            sum1 = a1[i]*10 + a3[j];
            sum2 = a3[i]*10 + a1[j];
            s.push_back(sum1);
            s.push_back(sum2);
        }
        //遍历
        //两个筛子 a3 a2
        for(int i = 0;i < 6;i ++) 
        for(int j = 0;j < 6;j ++)
        {
            sum1 = a2[i]*10 + a3[j];
            sum2 = a3[i]*10 + a2[j];
            s.push_back(sum1);
            s.push_back(sum2);
        }  
        //遍历三个筛子
        for(int i = 0;i < 6;i ++)
         for(int j = 0;j < 6;j ++)
         for(int k = 0;k < 6;k ++)
         {
             //1 2 3
             sum1 = a1[i]*100 + a2[j]*10 + a3[k];
             s.push_back(sum1);
             //1 3 2
             sum2 = a1[i]*100 + a3[j]*10 + a2[k];
             s.push_back(sum2);
             //2 3 1
             sum3 = a2[i]*100 + a3[j]*10 + a1[k];
             s.push_back(sum3);
             //2 1 3
             sum4 = a2[i]*100 + a1[j]*10 + a3[k];
             s.push_back(sum4);
             //3 1 2
             sum5 = a3[i]*100 + a1[j]*10 + a2[k];
             s.push_back(sum5);
             //3 2 1
             sum6 = a3[i]*100 + a2[j]*10 + a1[k];
             s.push_back(sum6);
         }
         sort(s.begin(),s.end());
         s.erase(unique(s.begin(),s.end()),s.end());
         cout << s.size() << '\n';
         vector<int>().swap(s);  
    }
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值