CF #502

#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define sz size()
#define be begin()
#define mp make_pair
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define rep(i,x,n) for(int i=(x); i<=(n); i++)
#define in freopen("in.in","r",stdin)
#define out freopen("out.out","w",stdout)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const ULL base = 100000007;//33951943
const int INF = 0x3f3f3f3f;
const LL LNF = 1e18;
const int maxn = 1e3+20;
const int maxm = 1e5 + 10;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int dx[] = {-1,1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
int dir[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n;
struct node
{
    int id;
    LL score;
}a[maxn];
bool cmp(node a,node b)
{
    if(a.score==b.score) return a.id<b.id;
    else return a.score>b.score;
}
int main()
{
    int x;
    int A,B,C,D;
    while(~scanf("%d",&n))
    {
        ms(a,0);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d%d",&A,&B,&C,&D);
            a[i].score=A+B+C+D;
            a[i].id=i;
        }
        sort(a+1,a+n+1,cmp);
        for(int i=1;i<=n;i++)
        {
            if(a[i].id==1)
            {
                cout<<i<<endl;break;
            }
        }
    }
    return 0;
}
/*
【题意】按照总分为主关键字,id 为次关键字排序,然后 O(n) 扫一遍找到 id 为 1 的学生的排名。

【类型】结构体排序

【分析】

【时间复杂度&&优化】

【trick】

【数据】
*/
A
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define sz size()
#define be begin()
#define mp make_pair
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define rep(i,x,n) for(int i=(x); i<=(n); i++)
#define in freopen("in.in","r",stdin)
#define out freopen("out.out","w",stdout)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const ULL base = 100000007;//33951943
const int INF = 0x3f3f3f3f;
const LL LNF = 1e18;
const int maxn = 5e5+20;
const int maxm = 1e5 + 10;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int dx[] = {-1,1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
int dir[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n;
LL ans=0;
char a[100005],b[100005];
/*
5
01011
11001
*/
int main()
{
    while(~scanf("%d%s%s",&n,a+1,b+1))
    {
        ans=0;
        LL c1=0,c2=0,c3=0,c0=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i]=='0'&&b[i]=='0') c0++;
            if(a[i]=='1'&&b[i]=='1') c1++;
            if(a[i]=='1'&&b[i]=='0') c2++;
            if(a[i]=='0'&&b[i]=='1') c3++;
        }
        cout<<c0*(c1+c2)+c2*c3<<endl; //{00—01 or 11 && 10-01}
    }
    return 0;
}
/*
【题意】
给定由 n 个 01 位组成的二进制数 a 和 b,问对 a 的所有 01 位有多少种交换不同位的方式,使得 a or b(按位或)的值发生改变。

【类型】
组合数学

【分析】

【时间复杂度&&优化】

【trick】

【数据】
*/
B
原文地址:https://www.cnblogs.com/Roni-i/p/9451618.html