zoj 3672 思考题

http://acm.zju.edu.cn/onlinejudge/showProblem.do?

problemId=4915

真是老了。脑子不会动了,可是事实上就算如今搜了题解A了,还是没总结出思维方式

三点:

1、segma(a[i]-b[i])必须是偶数。。由于事实上每次操作都是相当于从segma(a[i]-b[i])里面减去2*delta

2、a[i]>=b[i] 题目说的非常清楚,仅仅能减去。所以这点必须满足

前两点都想到了。可是自己能举出反例,后来队友A掉了

3、max(a[i]-b[i]) * 2  <= segma(a[i]-b[i])  否则的话。最大的肯定消不掉

可是事实上还是没有总结出思维方法,我一直做的都是。自己从小的样例枚举,找方法,然后推广至大的。可是好像不行这次

可能须要从反例里面多总结规律。然后假设自己反例都想出来都能应对。应该就对了

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <queue>
using namespace std;

#define ls(rt) rt*2
#define rs(rt) rt*2+1
#define ll long long
#define ull unsigned long long
#define rep(i,s,e) for(int i=s;i<e;i++)
#define repe(i,s,e) for(int i=s;i<=e;i++)
#define CL(a,b) memset(a,b,sizeof(a))
#define IN(s) freopen(s,"r",stdin)
#define OUT(s) freopen(s,"w",stdout)
const ll ll_INF = ((ull)(-1))>>1;
const double EPS = 1e-8;
const int INF = 100000000;

const int MAXN = 10000+100;
ll a[MAXN],b[MAXN];
ll vis[MAXN];
int n;

int main()
{
    while(~scanf("%d",&n))
    {
        CL(vis,0);
        int flag=1;
        ll mmax=0,ret=0;
        for(int i=0;i<n;i++)
        {
            scanf("%lld%lld",&a[i],&b[i]);
            if(a[i]<b[i])flag=0;
            if(a[i]>=b[i])vis[i]=a[i]-b[i];
            mmax=max(vis[i],mmax);
            ret+=vis[i];
        }
        if(flag==0 || 2*mmax >ret || ret%2)
            printf("NO\n");
        else
            printf("YES\n");

    }
    return 0;
}
时间: 2024-08-26 08:16:33

zoj 3672 思考题的相关文章

zoj 3672 思维题

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4915 真是老了,脑子不会动了,但是其实就算现在搜了题解A了,还是没总结出思维方式 三点: 1.segma(a[i]-b[i])必须是偶数,,因为其实每次操作都是相当于从segma(a[i]-b[i])里面减去2*delta 2.a[i]>=b[i] 题目说的很清楚,只能减去,所以这点必须满足 前两点都想到了,但是自己能举出反例,后来队友A掉了 3.max(a[i]-b[i])

ZOJ Monthly, November 2012

A.ZOJ 3666 Alice and Bob 组合博弈,SG函数应用 #include<vector> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn = 10000 + 100; int SG[maxn]; vector<int> g[maxn]; int mex(int u) { //minimal exc

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

zoj 2156 - Charlie&#39;s Change

题目:钱数拼凑,面值为1,5,10,25,求组成n面值的最大钱币数. 分析:dp,01背包.需要进行二进制拆分,否则TLE,利用数组记录每种硬币的个数,方便更新. 写了一个 多重背包的 O(NV)反而没有拆分快.囧,最后利用了状态压缩优化 90ms: 把 1 cents 的最后处理,其他都除以5,状态就少了5倍了. 说明:貌似我的比大黄的快.(2011-09-26 12:49). #include <stdio.h> #include <stdlib.h> #include <

ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 最小生成树 Kruskal算法

题目链接:ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 Building a Space Station Time Limit: 2 Seconds      Memory Limit: 65536 KB You are a member of the space station engineering team, and are assigned a task in the construction process of the statio

ZOJ 3607 Lazier Salesgirl (贪心)

Lazier Salesgirl Time Limit: 2 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy

ZOJ - 2243 - Binary Search Heap Construction

先上题目: Binary Search Heap Construction Time Limit: 5 Seconds      Memory Limit: 32768 KB Read the statement of problem G for the definitions concerning trees. In the following we define the basic terminology of heaps. A heap is a tree whose internal n

ZOJ 2859 二维线段树

思路:自己写的第二发二维线段树1A,哈哈,看来对二维的push操作比较了解了:但是还没遇到在两个线段树中同时进行push操作的,其实这题我是想在x维和y维同时进行push操作的,但是想了好久不会,然后看到这题又给出10秒,然后想想在x维线段直接单点查询肯定也过了,然后在第二维就只有pushup操作,在第一维线段树没有pushup操作.要是在第一维也有pushup操作的话,那就不用单点查询那么慢了.不过也A了,想找题即在二维同时进行pushup和pushdown操作的. #include<iost

ZOJ 2588

求一个无向图的桥(可能存在重边),输出割边的数目,并按顺序输出割边的序号(输入的顺序). 由于内存的限制 , 无法使用邻接矩阵 , 只能用邻接表了 . 第一次用了邻接表,超内存了: 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <string.h> 5 using namespace std; 6 const int N=10002; 7 const i