2016江南大学ACM俱乐部招新赛

匆忙而简捷地办完了年度招新活动,实现了第一次JNUOJ线上赛

Ranklist

  • 搭建OJ时不能实现预期中的多服务器并行处理,但评测效率已满足需求

  • VJ始终无法使用,不知原BNUOJ开发者是否会继续维护

  • 命题未免太强调难度了


A. 篱笆和人

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
const int N=100005;
const int mod=1e9+7;
typedef struct node
{
    int x,y;
    bool operator < (const node &other) const
    {
        if(x!=other.x)
         return y 



B. Water Problem

面向新人的提示:不必使用循环结构……

#include 
#include 
#include 
using namespace std;
int main()
{
    long long  t;
    while(scanf("%lld",&t)!=EOF)
    {
       if(!(t%2))
       {
           printf("%lld\n",((t/2-1)/2));
       }
       else
       {
           printf("0\n");
       }
    }
    return 0;
}

C. 交点

已知不存在三线交于一点的情况。圆内一个交点就可由两条线段决定,两条线段又由圆上的四个不同点决定。从圆上选取4个点的组合, $ C^4_n = \frac{n(n-1)(n-2)(n-3)}{24}$。另还有圆上的n个点要计算。

T=int(input())

while T>0:
    T-=1
    n=int(input())
    print n+n*(n-1)*(n-2)*(n-3)/24

D. 食物处理器

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
const int N=100005;
const int mod=1e9+7;
int val[N];
int main()
{
    int k,n,h,c;
    long long time=0;
    while(scanf("%d %d %d",&n,&h,&k)!=EOF)
    {
        c=0,time=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&val[i]);
        }
        for(int i=1;i<=n;i++)
        {
            while(c+val[i]>h)
            {
                if(c>k)
                {
                    int qwe=c;
                    qwe/=k;
                    time+=qwe;
                    c=c%k;
                }
                else
                {
                    c-=k;
                    if(c<0)
                        c=0;
                    time++;
                }
            }
            c+=val[i];
        }
        time+=c/k;
        if(c%k!=0)
        {
            time++;
        }
        cout< 


E. 最大计算值

#include
#include
#include
using namespace std;
char s[111];
int num[111];
int dp[111][111];
char cal[111];
int calu(int a,int b,char c)
{
    if(c=='*')
        return a*b;
    else if(c=='+')
        return a+b;
    else if(c=='-')
        return a-b;
}
int main()
{
    int T;
    scanf("%d",&T);
    for(int i=0;i='0'&&s[i]<='9')
            {
                k*=10;
                k+=s[i]-'0';
                i++;
            }
            dp[len++][len-1]=k;
            cal[len-1]=s[i];
        }
        for(int i=2;i<=len;i++)
        {
            for(int l=0;l=len)break;
                for(int k=l;k 


F. 有趣的字符串

#include
using namespace std;
const int maxn=100005;

char s[maxn];
int a[maxn];
int n,k;

int work(){
    int s=0,t=0,ans=0;
    int cnt=0;
    while( s<=t ){
        while( cnt<=k &&t 

稍暴力些的做法也可:

#include
using namespace std;
const int maxn=100005;

char s[maxn];
int a[maxn];
int n,k;
int dp[maxn];

int work(){
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j++){
            int tmp=dp[j]-dp[i-1];
            if(tmp<=k)
            ans=max(ans,j-i+1);
        }
    }

    return ans;
}


int main()
{
     int t;
     scanf("%d",&t);
     while(t--){
        scanf("%d%d",&n,&k);
        scanf("%s",s);
        //cout<<"haha"< 


G. 我的世界

/** Sep 19, 2015 7:12:36 PM
 * PrjName:Bc56-01
 * @author Semprathlon
 */
import java.io.*;
import java.util.*;
public class Main {

    /**
     * @param args
     */
    final static int maxn=110;
    static int cnt;
    static int[] w;
    static HashMap mp=new HashMap();
    public static void main(String[] args){
        // TODO Auto-generated method stub
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        int T=in.nextInt();
        //h=new int[maxn];
        w=new int[maxn];
        while(T-->0){
            int n=in.nextInt();
            cnt=0;
            mp.clear();
            Arrays.fill(w, 0);
            for(int i=1;i<=n;i++){
                int k=in.nextInt();
                if (mp.containsKey(k))
                    w[mp.get(k)]+=in.nextInt();
                else{
                    w[cnt]+=in.nextInt();
                    mp.put(k, cnt++);
                }
            }
            int sum=0;
            for(int i=0;i 


H. 尼古拉斯和数组

#include 
#include
#include
#include
#include
using namespace std;
const int maxn=105;
int num[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(num,0,sizeof(num));
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&num[i]);
        }
        int minpos=0;
        int maxpos=0;
        for(int i=1;i<=n;i++)
        {
            if(num[i]==1)
            {
                minpos=i;
            }
            if(num[i]==n)
            {
                maxpos=i;
            }
        }
        int len=0;
        len=abs(maxpos-minpos);
        int ans=0;
        if(len==n-1)
        {
            ans=n-1;
        }
        else
        {
            ans=max(ans,abs(maxpos-1));
            ans=max(ans,abs(n-maxpos));
            ans=max(ans,abs(minpos-1));
            ans=max(ans,abs(minpos-n));
        }
        cout << ans << endl;
    }
    return 0;
}

I. 奇妙的&操作

#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const ll mod=1000000007;
char s[111111];
int cal(int num)
{
    int res=6;
    for(int i=0; i<6; i++)
        if((1<='0'&&s[i]<='9')
                num=s[i]-'0';
            else if(s[i]>='a'&&s[i]<='z')
                num=s[i]-'a'+36;
            else if(s[i]>='A'&&s[i]<='Z')
                num=s[i]-'A'+10;
            else if(s[i]=='-')
                num=62;
            else
                num=63;
            int k=cal(num);
            while(k--)
            {
                ans*=3;
                ans%=mod;
            }
            ans%=mod;
        }
        //cout< 


J. 推箱子

【题意存疑】
怎样在单个地读入字符时排除换行符的影响?

#include 
#include 
#include 
#include 
#include 

using namespace std;

int main()
{
    char y,x;
    int n;
    while(scanf(" %c ",&y)!=EOF)
    {
        scanf("%d",&n);
        if(n&1)
        {
            if(y=='A')
                printf("B\n");
            else
                printf("A\n");
        }
        else
        {
            printf("%c\n",y);
        }
    }
    return 0;
}

【160610】服务器管理记录

  • Ubuntu查看运行中的进程及其id、监听端口

    sudo netstat -anp

  • 查询进程id

    pidof

  • 安全终止某个进程

    kill -15

  • 后台运行某个进程

    nohup&

内存空间不足的临时解决办法
How To Create A Swap File In Linux

linux下由于内存不足造成的 virtual memory exhausted: Cannot allocate memory, qt **.o文件 file not found

configure-apache-to-listen-on-port-other-than-80

http://askubuntu.com/questions/256013/could-not-reliably-determine-the-servers-fully-qualified-domain-name

Wordpress 更新错误

刚才升级到WP 4.5.2的时候报了个错,无法复制文件

就像这样,然而并不是权限设置的错。

其实是虚拟主机空间不够了。

atom编码简记

尝试转入这个github推荐的代码编辑器。

宣传视频非常有趣。

github平台的依托下,Atom在主题风格、插件扩展上异常灵活。

甚至提供apm install atom-beautify这种命令行安装扩展的方式。

在Eclipse中查看jdk源代码

为了帮助初学Java的同学,现给出查看jdk源代码的提示:

相关文件为$JAVA_HOME$/src.zip

POJ 1177 矩形周长并 扫描线

  • 计算当前扫描线上“进出”矩形的次数,乘上对应“事件”的边长。
/* 
 * File:   main.cpp
 * Author: semprathlon
 *
 * Created on April 26, 2016, 7:18 PM
 */

#include 
#include 
#include 
#include 
#include 

using namespace std;

struct Rectangle{
    int x1,y1,x2,y2;
    Rectangle(){}
    Rectangle(int _x1,int _y1,int _x2,int _y2):x1(_x1),x2(_x2),y1(_y1),y2(_y2){}
};

vector rects;

bool cmp(const int& a,const int& b){
    if (abs(a-b)<1e-5)
        return 0;
    return a-b<0;
}

int unionPerimeterY(const vector& rects){
    if (rects.empty()) return 0;
    typedef pair > Event;
    vector events;
    vector ys;
    for(int i=0;iy2) swap(y1,y2);
            sum[y1]+=delta;
            sum[y2]-=delta;
        
            int cnt=0,tmp=0;
            for(int j=0;j& rects){
    if (rects.empty()) return 0;
    typedef pair > Event;
    vector events;
    vector xs;
    for(int i=0;ix2) swap(x1,x2);
            sum[x1]+=delta;
            sum[x2]-=delta;
        
            int cnt=0,tmp=0;
            for(int j=0;j>n){
        if (!n) break;
        rects.clear();
        for(int i=0;i>x1>>y1>>x2>>y2;
            rects.push_back(Rectangle(x1,y1,x2,y2));
        }
        cout< 

POJ 1151 / hdu 1828 矩形面积并 扫描线+线段树

  • 应将线段树存储区间对应于矩形边的区段。
/*
 * File:   main.cpp
 * Author: semprathlon
 *
 * Created on April 9, 2016, 10:19 AM
 */

#include 
#include 
#include 
#include 
#include 

using namespace std;

struct Rectangle{
    double x1,y1,x2,y2;
    Rectangle(){}
    Rectangle(double _x1,double _y1,double _x2,double _y2):x1(_x1),x2(_x2),y1(_y1),y2(_y2){}
};

vector rects;
vector ys;

struct SegTree{
    SegTree *lchild,*rchild;
    int l,r,m;
    double s;
    int w;
    SegTree(){}
    SegTree(int _l,int _r):l(_l),r(_r){
        m=(l+r)>>1;w=0;s=0;
        if (l0)
        s=lchild->s+rchild->s;
    }
    void down(){
        if (w>0){
            lchild->w+=w;
            rchild->w+=w;
            if (lchild->w)
                lchild->s=ys[lchild->r+1]-ys[lchild->l];
            if (rchild->w)
                rchild->s=ys[rchild->r+1]-ys[rchild->l];
            s=w=0;
        }
    }
    void modify(int x,int y,int v){
        if (l==r){
            w+=v;
            if (w>0)
                s=ys[r+1]-ys[l];
            else
                s=0;
            return;
        }
        if (x==l&&r==y){
            w+=v;
            if (w>0){
                s=ys[r+1]-ys[l];
                return;
            }
            else
                s=0;
        }
        down();
        if (x<=m)
            lchild->modify(x,min(m,y),v);
        if (y>m)
            rchild->modify(max(m+1,x),y,v);
        up();
    }
    double query(int x,int y){
        //cout<<"q "<0?s:0;
        if (x==l&&r==y&&w>0){
            return s;
        }
        down();
        double res=0;
        if (x<=m) res+=lchild->query(x,min(m,y));
        if (y>m) res+=rchild->query(max(m+1,x),y);
        up();
        return res;
    }
} *T;

bool cmp(const double& a,const double& b){
    if (abs(a-b)<1e-5)
        return 0;
    return a-b<0;
}

double unionArea(const vector& rects){
    if (rects.empty()) return 0;
    typedef pair > Event;
    vector events;
    ys.clear();
    for(int i=0;i cnt(ys.size()-1,0);
    for(int i=0;iy2) swap(y1,y2);
        T->modify(y1,y2-1,delta);
        //for(int j=0;jquery(j,j);
            //cout<query(j,j)<query(0,ys.size()-2);
//        cout<>n){
        if (!n) break;
        rects.clear();
        for(int i=0;i>x1>>y1>>x2>>y2;
            rects.push_back(Rectangle(x1,y1,x2,y2));
        }
        cout<<"Test case #"<<++cas<