福州大学第十四届程序设计竞赛 (题解)

To Be honset   夫走大学的  判题机是真心的烂,对STL库支持是如此的差,仍然在c++5.1---   bits/stdc++.h 头文件不支持

对于打多了CF的我来说 相当不友好, STL库 vector 动不动就超时超内存,pair也不敢用, 这能对着queue瑟瑟发抖.

习惯了直接cin,  不习惯EOF 了.


A - 奖励

  FZU - 2258 

福州大学某班共有n名学生,这些学生这学期都选修了3门课,分别是大物、高数、大英。YellowStar想对这学期总绩点不低于3.0的学生进行奖励,所以他将每名学生每门课程的分数告诉你,并希望你能告诉他他必须对多少名学生进行奖励。

对于单门课程的绩点计算方法是(分数/10-5),如分数是69,那么绩点就是1.9,学生的总绩点就是他每门课程的绩点的平均值。但是要注意的是,当某门课程的分数小于60时,就会被视为挂科,总绩点直接为0。

Input

包含多组测试数据。

第一行输入一个整数n,表示一共有n名学生。

接下来输入n行,每行3个整数,分别表示当前学生的3门课程的分数,分数都不大于100且不小于0。

n≤500000

Output

输出一个整数,表示有多少人的总绩点不低于3.0。

Sample Input
3
59 50 92
60 80 97
83 94 67
Sample Output
1
Hint
第一名同学有低于60分的科目,所以总绩点为0。 第二名同学的总绩点为(1+3+4.7)/3=2.9 第三名同学的总绩点为(3.3+4.4+1.7)/3约为3.13 只有最后一名同学的总绩点超过3.0

[此题]

时间卡的是真滴好, 第一次交,头文件问题编译错误,第二次数组限,第三次超时.  / 法不行, 必须改成 +法

//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <stdlib.h>

#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x,b,n) lower_bound(b+1,b+1+n,x)-b
#define FIN      freopen("input.txt","r",stdin)
#define FOUT     freopen("output.txt","w",stdout)
#define SHUT ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define  FI(n) IO::read(n)
#define  Be IO::begin()

using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MAXN=50005;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};

/*namespace IO {
	const int MT = 5e7;
	char buf[MT]; int c,sz;
	void begin(){
		c = 0;
		sz = fread(buf, 1, MT, stdin);//一次性输入
	}
	template<class T>
	inline bool read(T &t){
		while( c < sz && buf[c] != '-' && ( buf[c]<'0' || buf[c] >'9')) c++;
		if( c>=sz) return false;
		bool flag = 0; if( buf[c]== '-') flag = 1,c++;
		for( t=0; c<=sz && '0' <=buf[c] && buf[c] <= '9'; c++ ) t= t*10 + buf[c]-'0';
		if(flag) t=-t;
		return true;
	}
}*/


int main()
{
    int n;
    int x,y,z;
    while((scanf("%d",&n))!=EOF)
    {
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            int sum=0;
            scanf("%d %d %d",&x,&y,&z);
            sum+=x;
            sum+=y;
            sum+=z;
            if(x<60||y<60||z<60)
                sum=0;
           // cout<<sum<<endl;
            if(sum>=240)
                ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}
/*3
60 60 60
60 60 60
60 60 60*/

海边躺着一排咸鱼,一些有梦想的咸鱼成功翻身(然而没有什么卵用),一些则是继续当咸鱼。一个善良的渔夫想要帮这些咸鱼翻身,但是渔夫比较懒,所以只会从某只咸鱼开始,往一个方向,一只只咸鱼翻过去,翻转若干只后就转身离去,深藏功与名。更准确地说,渔夫会选择一个区间[L,R],改变区间内所有咸鱼的状态,至少翻转一只咸鱼。

渔夫离开后想知道如果他采取最优策略,最多有多少只咸鱼成功翻身,但是咸鱼大概有十万条,所以这个问题就交给你了!

Input

包含多组测试数据。

每组测试数据的第一行为正整数n,表示咸鱼的数量。

第二行为长n的01串,0表示没有翻身,1表示成功翻身。

n≤100000

Output

在渔夫的操作后,成功翻身咸鱼(即1)的最大数量。

Sample Input
5
1 0 0 1 0
3
0 1 0
Sample Output
4
2
Hint

对于第一个样例,翻转区间[2,3],序列变为1 1 1 1 0。

对于第二个样例,翻转整个区间,序列变为1 0 1。


[思路]

 第一眼,没看出来,第二眼,还没看出来,第三眼,好吧, 就时没看出来, 此题一个坑,至少翻一次,当全是1时

输出n-1

1对翻转总贡献为-1 ,0的贡献+1 所以就是最大字段和的问题了, 最大字段和是翻转得到的+ 已有的就是答案

[代码]

//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x,b,n) lower_bound(b+1,b+1+n,x)-b
#define FIN      freopen("input.txt","r",stdin)
#define FOUT     freopen("output.txt","w",stdout)
#define SHUT ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define  FI(n) IO::read(n)
#define  Be IO::begin()

using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MAXN=100005;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};

/*namespace IO {
	const int MT = 5e7;
	char buf[MT]; int c,sz;
	void begin(){
		c = 0;
		sz = fread(buf, 1, MT, stdin);//一次性输入
	}
	template<class T>
	inline bool read(T &t){
		while( c < sz && buf[c] != '-' && ( buf[c]<'0' || buf[c] >'9')) c++;
		if( c>=sz) return false;
		bool flag = 0; if( buf[c]== '-') flag = 1,c++;
		for( t=0; c<=sz && '0' <=buf[c] && buf[c] <= '9'; c++ ) t= t*10 + buf[c]-'0';
		if(flag) t=-t;
		return true;
	}
}
ll inv[maxn*2];
inline void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){ x=1; y=0; d=a; }else{ ex_gcd(b,a%b,d,y,x); y-=x*(a/b);};}
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll ans=exgcd(b,a%b,x,y);ll temp=x;x=y;y=temp-a/b*y;return ans;}
inline ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}
inline ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}
inline ll inv_exgcd(ll a,ll n){ll d,x,y;ex_gcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}
inline ll inv1(ll b){return b==1?1:(MOD-MOD/b)*inv1(MOD%b)%MOD;}
inline ll inv2(ll b){return qpow(b,MOD-2);}*/

int b[MAXN];
int a[MAXN];
int dp[MAXN];
int main()
{
    int n;
    while((scanf("%d",&n))!=EOF)
    {
        mem(dp,0);
        mem(a,0);
        mem(b,0);
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]==1)
                sum++;
        }

        if(sum==n)
        {
            printf("%d\n",n-1);
            continue;
        }
        for(int i=1;i<=n;i++)
        {
            if(a[i])
                b[i]=-1;
            else
                b[i]=1;
        }
        int maxx=-INF;
        for(int i=1;i<=n;i++)
        {
            dp[i]=dp[i-1]+b[i];
            if(dp[i]<0)
                dp[i]=0;
            if(maxx<dp[i])
                maxx=dp[i];
        }
        printf("%d\n",maxx+sum);
    }
    return 0;
}


C - 浪里个浪

  FZU - 2261 


TonyY是一个喜欢到处浪的男人,他的梦想是带着兰兰姐姐浪遍天朝的各个角落,不过在此之前,他需要做好规划。

现在他的手上有一份天朝地图,上面有n个城市,m条交通路径,每条交通路径都是单行道。他已经预先规划好了一些点作为旅游的起点和终点,他想选择其中一个起点和一个终点,并找出从起点到终点的一条路线亲身体验浪的过程。但是他时间有限,所以想选择耗时最小的,你能告诉他最小的耗时是多少吗?

Input

包含多组测试数据。

输入第一行包括两个整数n和m,表示有n个地点,m条可行路径。点的编号为1 - n。

接下来m行每行包括三个整数i, j, cost,表示从地点i到地点j需要耗时cost。

接下来一行第一个数为S,表示可能的起点数,之后S个数,表示可能的起点。

接下来一行第一个数为E,表示可能的终点数,之后E个数,表示可能的终点。

0<S, E≤n≤100000,0<m≤100000,0<cost≤100。

Output

输出他需要的最短耗时。

Sample Input
4 4
1 3 1
1 4 2
2 3 3
2 4 4
2 1 2
2 3 4
Sample Output
1

[思路]

S次 SPFA 时间复杂度为S*Nlog(N) 大于1200ms

把S所有的起点放到队列里跑一次SPFA 时间 300ms

[代码]

//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x,b,n) lower_bound(b+1,b+1+n,x)-b
#define FIN      freopen("input.txt","r",stdin)
#define FOUT     freopen("output.txt","w",stdout)
#define SHUT ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define  FI(n) IO::read(n)
#define  Be IO::begin()

using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MAXN=100005;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};

/*namespace IO {
	const int MT = 5e7;
	char buf[MT]; int c,sz;
	void begin(){
		c = 0;
		sz = fread(buf, 1, MT, stdin);//一次性输入
	}
	template<class T>
	inline bool read(T &t){
		while( c < sz && buf[c] != '-' && ( buf[c]<'0' || buf[c] >'9')) c++;
		if( c>=sz) return false;
		bool flag = 0; if( buf[c]== '-') flag = 1,c++;
		for( t=0; c<=sz && '0' <=buf[c] && buf[c] <= '9'; c++ ) t= t*10 + buf[c]-'0';
		if(flag) t=-t;
		return true;
	}
}
ll inv[maxn*2];
inline void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){ x=1; y=0; d=a; }else{ ex_gcd(b,a%b,d,y,x); y-=x*(a/b);};}
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll ans=exgcd(b,a%b,x,y);ll temp=x;x=y;y=temp-a/b*y;return ans;}
inline ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}
inline ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}
inline ll inv_exgcd(ll a,ll n){ll d,x,y;ex_gcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}
inline ll inv1(ll b){return b==1?1:(MOD-MOD/b)*inv1(MOD%b)%MOD;}
inline ll inv2(ll b){return qpow(b,MOD-2);}*/

int head[MAXN];
int cot,vis[MAXN];
int dist[MAXN];
struct node{
    int v,w,next;
}edge[MAXN];
int n,m;
void init()
{
    cot=0;
    mem(head,-1);
}
void add(int u,int v,int w)
{
    edge[++cot].v=v;
    edge[cot].w=w;
    edge[cot].next=head[u];
    head[u]=cot;
}
int a[MAXN],b[MAXN];
void SPFA()
{
    queue<int>Q;
    mem(vis,0);
    for(int i=1;i<=n;i++)
    {
    	if(dist[i]==0)
    	{
    		Q.push(i);
    		vis[i]=1;
		}
	}    
    while(!Q.empty())
    {
        int u=Q.front();
        Q.pop();
        vis[u]=0;
        for(int i=head[u];i!=-1;i=edge[i].next)
        {
            int v=edge[i].v;
            int w=edge[i].w;
            if(dist[u]+w<dist[v])
            {
                dist[v]=dist[u]+w;
                if(!vis[v])
                {
                    vis[v]=1;
                    Q.push(v);
                }
            }
        }
    }

}
int main()
{
    while((scanf("%d %d",&n,&m))!=EOF)
    {
        init();
        int x,y,z;
        mem(a,0);
        mem(b,0);
        mem(dist,INF);
        for(int i=1;i<=m;i++)
        {
            scanf("%d %d %d",&x,&y,&z);
            add(x,y,z);
        }
        int ans=INF;
        scanf("%d",&x);
        for(int i=1;i<=x;i++)
        {
        	scanf("%d",&a[i]);
        	dist[a[i]]=0;
		}
            
        scanf("%d",&y);
        for(int i=1;i<=y;i++)
        {
        	scanf("%d",&b[i]);
        	
		}
        SPFA();           
        for(int j=1;j<=y;j++)
        {
              
             ans=min(ans,dist[b[j]]);
        }


        cout<<ans<<endl;
    }
    return 0;
}
/*
4 4
1 2 5
1 4 4
1 3 3
2 4 3
2 1 2
2 2 4
*/


某一天,YellowStar在人生的道路上迷失了方向,迷迷糊糊之中,它误入了一座迷宫中,幸运的是它在路口处发现了一张迷宫的地图。

经过它的观察,它发现这个迷宫一共有n个房间,并且这n个房间呈现一个有根树结构,它现在所在的1号房间为根,其它每个房间都有一个上级房间,连接第i个房间和它的上级房间Pi的道路长度为Wi。

在地图的背面,记载了这个迷宫中,每个房间拥有一个时空传送门,第i个房间的传送门可以花费Di单位的时间传送到它的任意一个下级房间中(如果x是y的下级房间,并且y是z的下级房间,那么x也是z的下级房间)。

YellowStar的步行速度为1单位时间走1长度,它现在想知道从1号房间出发,到每一个房间的最少时间。

Input

包含多组测试数据。

第一行输入n表示n个房间。

第二行输出n个数字,第i个数字Di表示i号房间传送器需要花费的时间。

接下来n-1行,第i行包含两个数字Pi和Wi,表示i+1号房间的上级房间为Pi,道路长度为Wi。

1≤n≤100000

1≤Di, Wi≤10^9

Output

输出n个数,第i个数表示从1号房间出发到i号房间的最少时间。 (注意,输出最后一个数字后面也要加一个空格)

Sample Input
5
99 97 50 123 550
1 999
1 10
3 100
3 44
Sample Output
0 99 10 60 54
Hint

初始在1号房间,到1号房间的代价为0。

通过1号房间的传送门传送到2号房间,到2号房间的代价为99。

通过1号房间走到3号房间,到3号房间的代价为10。

通过1号房间走到3号房间,在通过3号房间的传送门传送到4号房间,到4号房间的代价为60。

通过1号房间走到3号房间,在通过3号房间走到5号房间,到5号房间的代价为54。


[思路]

用BFS跑一遍, 示例过了 还是不对. 改成DFS --> 跑, 每次  到这个点 有两种  一个是 直接传送, 一个是 走过来, 走过来是用上一个点,  对于上一个点 又有 传送过来和 上上一个点走过来

[代码]

//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x,b,n) lower_bound(b+1,b+1+n,x)-b
#define FIN      freopen("input.txt","r",stdin)
#define FOUT     freopen("output.txt","w",stdout)
#define SHUT ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define  FI(n) IO::read(n)
#define  Be IO::begin()

using namespace std;
typedef long long ll;
const double PI=acos(-1);
const ll INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MAXN=100005;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};

/*namespace IO {
	const int MT = 5e7;
	char buf[MT]; int c,sz;
	void begin(){
		c = 0;
		sz = fread(buf, 1, MT, stdin);//一次性输入
	}
	template<class T>
	inline bool read(T &t){
		while( c < sz && buf[c] != '-' && ( buf[c]<'0' || buf[c] >'9')) c++;
		if( c>=sz) return false;
		bool flag = 0; if( buf[c]== '-') flag = 1,c++;
		for( t=0; c<=sz && '0' <=buf[c] && buf[c] <= '9'; c++ ) t= t*10 + buf[c]-'0';
		if(flag) t=-t;
		return true;
	}
}
ll inv[maxn*2];
inline void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){ x=1; y=0; d=a; }else{ ex_gcd(b,a%b,d,y,x); y-=x*(a/b);};}
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll ans=exgcd(b,a%b,x,y);ll temp=x;x=y;y=temp-a/b*y;return ans;}
inline ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}
inline ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}
inline ll inv_exgcd(ll a,ll n){ll d,x,y;ex_gcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}
inline ll inv1(ll b){return b==1?1:(MOD-MOD/b)*inv1(MOD%b)%MOD;}
inline ll inv2(ll b){return qpow(b,MOD-2);}*/

int head[MAXN];
int cot,vis[MAXN];
ll dist[MAXN];
struct node{
    ll v,next;
    ll w;
}edge[MAXN];
int n,m;
void init()
{
    cot=0;
    mem(head,-1);
}
void add(int u,int v,ll w)
{
    edge[++cot].v=v;
    edge[cot].w=w;
    edge[cot].next=head[u];
    head[u]=cot;
}
ll a[MAXN],b[MAXN],z[MAXN];
void SPFA(int st,ll c1,ll c2)
{
    dist[st]=min(c1,c2);

    for(ll i=head[st];i!=-1;i=edge[i].next)
    {
        ll v=edge[i].v;
        ll w=edge[i].w;
        SPFA(v,min(dist[st]+a[st],c1),w+dist[st]);
    }

}
int main()
{
    while((scanf("%d",&n))!=EOF)
    {
        init();

        mem(a,0);
        mem(b,0);
        mem(dist,INF);
        for(int i=1;i<=n;i++)
        {
            scanf("%I64d",&a[i]);
        }
        for(int i=2;i<=n;i++)
        {
            scanf("%I64d %I64d",&b[i],&z[i]);
            add(b[i],i,z[i]);
        }
        SPFA(1,INF,0);
        for(int i=1;i<=n;i++)
        {
            printf("%I64d ",dist[i]);
        }
        printf("\n");
    }
    return 0;
}

象棋翻翻棋(暗棋)中双方在4*8的格子中交战,有时候最后会只剩下帅和将。根据暗棋的规则,棋子只能上下左右移动,且相同的级别下,主动移动到地方棋子方将吃掉对方的棋子。将和帅为同一级别。然而胜负在只剩下帅和将的时候已定。

Input

第一行T,表示T组数据。

每组数据共有四行字符串,每行字符串共八个字符

’#’表示空格

’*’表示红方帅

’.’表示黑方将

此时红方先走

每组输入之间没有空行。

Output

每组数据输出一行。若为红方赢输出Red win,否则输出 Black win

Sample Input
1
######.#
#####*##
########
########
Sample Output
Black win


[思路]

这个题,是个博弈, 简单的博弈, 两个坐标只差和 是奇偶问题. 很好分析, 只能4个方向, 对于当前状况,无论怎么走, 都会变成当前

这个局势, 红先走,必然注定结果.

[代码]

//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <stdlib.h>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x,b,n) lower_bound(b+1,b+1+n,x)-b
#define FIN      freopen("input.txt","r",stdin)
#define FOUT     freopen("output.txt","w",stdout)
#define SHUT ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define  FI(n) IO::read(n)
#define  Be IO::begin()

using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MAXN=100005;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};

/*namespace IO {
	const int MT = 5e7;
	char buf[MT]; int c,sz;
	void begin(){
		c = 0;
		sz = fread(buf, 1, MT, stdin);//一次性输入
	}
	template<class T>
	inline bool read(T &t){
		while( c < sz && buf[c] != '-' && ( buf[c]<'0' || buf[c] >'9')) c++;
		if( c>=sz) return false;
		bool flag = 0; if( buf[c]== '-') flag = 1,c++;
		for( t=0; c<=sz && '0' <=buf[c] && buf[c] <= '9'; c++ ) t= t*10 + buf[c]-'0';
		if(flag) t=-t;
		return true;
	}
}
ll inv[maxn*2];
inline void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){ x=1; y=0; d=a; }else{ ex_gcd(b,a%b,d,y,x); y-=x*(a/b);};}
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll ans=exgcd(b,a%b,x,y);ll temp=x;x=y;y=temp-a/b*y;return ans;}
inline ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}
inline ll qpow(ll x,ll n){ll res=1;for(;n;n>>=1){if(n&1)res=(res*x)%MOD;x=(x*x)%MOD;}return res;}
inline ll inv_exgcd(ll a,ll n){ll d,x,y;ex_gcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}
inline ll inv1(ll b){return b==1?1:(MOD-MOD/b)*inv1(MOD%b)%MOD;}
inline ll inv2(ll b){return qpow(b,MOD-2);}*/

 char maps[10][10];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int flag=1;
        for(int i=1;i<=4;i++)
        {
            scanf("%s",maps[i]);
        }
        int px=0,py=0,ax=0,ay=0;
        for(int i=1;i<=4;i++)
        {
            for(int j=0;j<=7;j++)
            {
                if(maps[i][j]=='.')
                {
                    px=i,py=j+1;
                }
                if(maps[i][j]=='*')
                {
                    ax=i,ay=j+1;
                }
            }
        }
        int sum=0;
       // cout<<px<<" "<<py<<" "<<ax<<" "<<ay<<endl;
        sum+= fabs(px-ax)+fabs(py-ay);
        // cout<<sum<<endl;
        if(sum%2==0)
        {
            printf("Black win\n");
        }
        else
            printf("Red win\n");

    }
    return 0;
}
/*
1
#####*.#
########
########
########
*/



在一个平面内给定n个点,任意三个点不在同一条直线上,用这些点可以构成多少个平行四边形?一个点可以同时属于多个平行四边形。

Input

多组数据(<=10),处理到EOF。

每组数据第一行一个整数n(4<=n<=500)。接下来n行每行两个整数xi,yi(0<=xi,yi<=1e9),表示每个点的坐标。

Output

每组数据输出一个整数,表示用这些点能构成多少个平行四边形。

Sample Input
4
0 1
1 0
1 1
2 0
Sample Output
1

[思路]

计算几何,---> 说了不存在3个以上的点在一条直线,

所以根据平行四边形的性质, 对于任意两个坐标和 中智相等的点 必然可以组成平行四边形

[再次吐槽 判题机] vector 一直WA,WA, 改怕了, 真怕了

[代码]

//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x,b,n) lower_bound(b+1,b+1+n,x)-b
#define FIN      freopen("input.txt","r",stdin)
#define FOUT     freopen("output.txt","w",stdout)
#define SHUT ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define  FI(n) IO::read(n)
#define  Be IO::begin()

using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MAXN=300005;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};

typedef pair<double,double> PAIR;
struct node{
    int first,second;
}V[MAXN],Q[MAXN];
int cmp(node a,node b)
{
    if(a.first==b.first)
        return a.second<b.second;
    return a.first<b.first;
}


int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
         for(int i=0;i<n;i++)
        {
            int x,y;
            scanf("%d %d",&V[i].first,&V[i].second);
        }
        int k=0;
        for(int i=0;i<n-1;i++)
        {
            for(int j=i+1;j<n;j++)
            {

                Q[k].first=V[i].first+V[j].first;
                Q[k++].second=V[i].second+V[j].second;

            }
        }
        sort(Q,Q+k,cmp);
        int ans=0;
        int num=1;
        for(int i=1;i<k;i++)
        {
              if(Q[i].first==Q[i-1].first&&Q[i].second==Q[i-1].second)
              {
                  num++;
              }
              else
              {
                  ans+= (num*(num-1))/2;
                  num=1;
              }
        }

       printf("%d\n",ans);
    }


    return 0;
}


G - 炉石传说

  FZU - 2232 

GG学长虽然并不打炉石传说,但是由于题面需要他便学会了打炉石传说。但是传统的炉石传说对于刚入门的GG学长来说有点复杂,所以他决定自己开发一个简化版的炉石传说。

在简化版的炉石传说中:

每个随从只有生命值和攻击力,并且在你的回合下,你的每只随从在本回合下只能选择一个敌方随从进行攻击。当两个随从a,b交战时,a的生命值将减去b的攻击力,b的生命值将减去a的攻击力,(两个伤害没有先后顺序,同时结算)。如果a或b的生命值不大于0,该随从将死亡。

某一次对局中,GG学长和对手场面上均有n个随从,并且是GG学长的回合。由于GG学长是个固执的boy,他一定要在本回合杀死对方所有随从,并且保证自己的随从全部存活。他想知道能否做到。

Input

第一行为T,表示有T组数据。T<=100。

每组数据第一行为n,表示随从数量(1 <= n <= 100)

接下来一行2 * n个数字a1, b1, a2, b2, ... , an, bn (1 <= ai, bi <= 100)

表示GG学长的n个随从,ai表示随从生命,bi表示随从攻击力

接下来一行2 * n个数字c1, d1, c2, d2, ... , cn, dn (1 <= ci, di <= 100)

表示对手的n个随从,ci表示随从生命,di表示随从攻击力。

Output

每组数据,根据GG是否能完成他的目标,输出一行”Yes”或”No”。

Sample Input
2
3
4 4 5 5 6 6
1 1 2 2 3 3
3
4 4 5 5 6 6
1 4 2 4 3 4
Sample Output
Yes
No

[思路]

有用二分匹配的, 我用的贪心, 我觉着贪心好理解. 己方排序, 从己方最弱的去找能够打死对方,而自己不死的这些之中

最大的那个 , 贪心策略, 但是一直WA,WA,WA,WA,WA

后来, 两个队伍的排序不一样,己方是按照生命力从小到大, 对方按照攻击力从小到大...

[代码]

//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <vector>
#define mem(a,b) memset(a,b,sizeof(a))
#define findx(x,b,n) lower_bound(b+1,b+1+n,x)-b
#define FIN      freopen("input.txt","r",stdin)
#define FOUT     freopen("output.txt","w",stdout)
#define SHUT ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r
#define  FI(n) IO::read(n)
#define  Be IO::begin()

using namespace std;
typedef long long ll;
const double PI=acos(-1);
const int INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MAXN=100005;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};


struct node{
    int x,y;
}V[MAXN],Q[MAXN];
int cmp(node a,node b)
{
    if(a.y==b.y)
        return a.x<b.x;
    return a.y<b.y;
}
int cmp2(node a,node b)
{
    if(a.x!=b.x)
        return a.x<b.x;
}
//vector<node>V,Q;
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        mem(V,0);
        mem(Q,0);
        scanf("%d",&n);
        int x,y;
        for(int i=1;i<=n;i++)
        {
        scanf("%d %d",&x,&y);
           V[i].x=x,V[i].y=y;
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d %d",&x,&y);
            Q[i].x=x,Q[i].y=y;
        }

        sort(V+1,V+n+1,cmp);
        sort(Q+1,Q+n+1,cmp2);
        int flag=1;
        int vis[MAXN];
        mem(vis,0);
        for(int i=1;i<=n;i++)
        {
            node IMX;
            IMX.x=-INF;
            IMX.y=-INF;
            int cow=0;
            for(int j=1;j<=n;j++)
            {
                if(V[i].x>Q[j].y&&V[i].y>=Q[j].x&&!vis[j])
                {
                    if(IMX.x<=Q[j].x&&IMX.y<=Q[j].y&&!vis[j])
                    {
                        cow=j;
                        IMX=Q[j];
                    }
                }
            }
            if(IMX.x!=-INF)
                vis[cow]=1;
        }
        for(int i=1;i<=n&&flag;i++)
        {
            if(vis[i]!=1)
                flag=0;
        }
        if(flag)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}

H - 第十四个目标

  FZU - 2236 

目暮警官、妃英里、阿笠博士等人接连遭到不明身份之人的暗算,柯南追踪伤害阿笠博士的凶手,根据几起案件现场留下的线索发现凶手按照扑克牌的顺序行凶。在经过一系列的推理后,柯南发现受害者的名字均包含扑克牌的数值,且扑克牌的大小是严格递增的,此外遇害者与毛利小五郎有关。

为了避免下一个遇害者的出现,柯南将可能遭到暗算的人中的数字按关联程度排列了出来,即顺序不可改变。柯南需要知道共有多少种可能结果,满足受害人名字出现的数字严格递增,但是他柯南要找出关键的证据所在,所以这个任务就交给你了。

(如果你看不懂上面在说什么,这题是求一个数列中严格递增子序列的个数。比如数列(1,3,2)的严格递增子序列有(1)、(3)、(2)、(1,3)、(1,2),共5个。长得一样的但是位置不同的算不同的子序列,比如数列(3,3)的答案是2。)

Input

多组数据(<=10),处理到EOF。

第一行输入正整数N(N≤100 000),表示共有N个人。

第二行共有N个整数Ai(1≤Ai≤10^9),表示第i个人名字中的数字。

Output

每组数据输出一个整数,表示所有可能的结果。由于结果可能较大,对1 000 000 007取模后输出。

Sample Input
3
1 3 2
Sample Output
5


[思路]

嗯,这个题 还没研究出来--







  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值