是題目呀

Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, this task has a difficulty level yi. The machine whose level below this task’s level yi cannot complete this task. If the company completes this task, they will get (500*xi+2*yi) dollars.
The company has n machines. Each machine has a maximum working time and a level. If the time for the task is more than the maximum working time of the machine, the machine can not complete this task. Each machine can only complete a task one day. Each task can only be completed by one machine.
The company hopes to maximize the number of the tasks which they can complete today. If there are multiple solutions, they hopes to make the money maximum.

Input

The input contains several test cases.
The first line contains two integers N and M. N is the number of the machines.M is the number of tasks(1 < =N <= 100000,1<=M<=100000).
The following N lines each contains two integers xi(0<xi<1440),yi(0=<yi<=100).xi is the maximum time the machine can work.yi is the level of the machine.
The following M lines each contains two integers xi(0<xi<1440),yi(0=<yi<=100).xi is the time we need to complete the task.yi is the level of the task.

Output

For each test case, output two integers, the maximum number of the tasks which the company can complete today and the money they will get.

Sample Input

1 2

100 3

100 2

100 1

Sample Output

1 50004

貪心,比較巧的貪心,利用兩個數組的單調性。

#include<cstdio>

#include<cstring>

#include<algorithm>

#include<iostream>

using namespace std;

#define ll long long

const int maxn=1e5+10;

struct node{

int x,y;

}nod[maxn],nodd[maxn];

bool cmp(node a,node b){

if(a.x==b.x) return a.y>b.y;

return a.x>b.x;

}

int main(){

int n,m;

while(scanf("%d%d",&n,&m)!=EOF){

for(int i=1;i<=n;i++){

scanf("%d%d",&nod[i].x,&nod[i].y);

}

for(int j=1;j<=m;j++){

scanf("%d%d",&nodd[j].x,&nodd[j].y);

}

int c[102]={0};//chushihua

sort(nod+1,nod+1+n,cmp);//

sort(nodd+1,nodd+1+m,cmp);//

ll res=0;int cnt=0;

for(int i=1,j=1;i<=m;i++){

while(j<=n&&nod[j].x>=nodd[i].x){

c[nod[j].y]++;

j++;

}

for(int k=nodd[i].y;k<=100;k++){

if(c[k]){

c[k]--;

res+=nodd[i].x*500+nodd[i].y*2;

cnt++;

break;//我之前少了

}

 

}

}

cout<<cnt<<" "<<res<<endl;

 

}

return 0;

 

}

In a two dimensional array of integers of size

2×n2 \times n

2×n, is it possible to rearrange integers so that the sum of two adjacent elements (which are adjacent in a common row or a common column) is never divisible by three?

Input

The input has several test cases and the first line contains an integer

t(1≤t≤200)t (1 \le t \le 200)

t(1≤t≤200) which is the number of test cases.

In each case, the first line contains an integers

n(1≤n≤10000)n (1 \le n \le 10000)

n(1≤n≤10000) indicating the number of columns in the array. The second line contains the elements of the array in the first row separated by single spaces. The third line contains the elements of the array in the second row separated by single spaces. The elements will be positive integers less then

10000001000000

1000000.

Output

For each test case, output “YES” in a single line if any valid rearrangement exists, or “NO” if not.

樣例輸入

複製

6

3

3 6 9

1 4 7

3

3 6 9

1 3 8

5

1 2 3 4 5

6 7 8 9 10

10

1 1 1 1 1 1 1 1 1 1

2 3 2 3 2 3 2 3 2 3  

2

3 1

2 3

2

3 1

1 2

樣例輸出

複製

YES

NO

YES

YES

YES

NO

#include<cstdio>

#include<iostream>

#include<cstring>

#include<algorithm>

using namespace std;

const int maxn=1e4+10;

int a[maxn];

int b[maxn];

int c[5];

int main(){

int t;

cin>>t;

while(t--){

int n;

memset(c,0,sizeof(c));

scanf("%d",&n);int x;

for(int i=1;i<=n;i++){

scanf("%d",&x);

c[x%3]++;

}

for(int i=1;i<=n;i++){

scanf("%d",&x);

c[x%3]++;

}

// for(int i=0;i<3;i++) cout<<c[i]<<endl;

bool flag=1;

if(c[0]>n||(c[0]<=1&&c[1]!=0&&c[2]!=0)) {

flag=0;

// cout<<"one"<<endl;

}

 

else if(c[0]==2&&c[1]%2==0&&c[2]%2==0){

flag=0;

}

 

if(!flag) cout<<"NO"<<endl;

else cout<<"YES"<<endl;

 

 

 

}

return 0;

}

這道題目,由於三個,兩個加起來可以被3整除,然後特徵是可以分塊,所以用0分開,然後特判兩個0的時候,因爲它本身的特殊性,然後,我之間亂寫一通,第一次就wa了,基本上着這種題目不可瞎寫

Welcome to the 2017 ACM-ICPC Asia Nanning Regional Contest.

Here is a breaking news. Now you have a chance to meet alone with the Asia Director through a game.

All boys and girls who chase their dreams have to stand in a line. They are given the numbers in the order in which they stand starting from

11

1.

The host then removes all boys and girls that are standing at an odd position with several rounds.

For example if there are

n=8n = 8

n=8 boys and girls in total. Initially standing people have numbers

1,2,3,4,5,6,71, 2, 3, 4, 5, 6, 7

1,2,3,4,5,6,7 and

88

8. After the first round, people left are

2,4,62,4,6

2,4,6 and

88

8. After the second round, only two people,

44

4 and

88

8, are still there.

The one who stays until the end is the chosen one.

I know you want to become the chosen one to meet alone with your idol. Given the number of boys and girls in total, can you find the best place to stand in the line so that you would become the chosen one?

Input

First line of the input contains the number of test cases

t(1≤t≤1000)t (1 \le t \le 1000)

t(1≤t≤1000).

Each of the next t lines contains the integer n which is the number of boys and girls in total, where

2≤n≤10502 \le n \le 10^{50}

2≤n≤10

50

.

Output

The output displays t lines, each containing a single integer which is the place where you would stand to win the chance.

#include<cstdio>

#include<iostream>

#include<algorithm>

#include<cstring>

const int maxn=55;

int a[maxn];

char b[maxn];

int c[maxn];

using namespace std;

int main(){

int t;

cin>>t;

while(t--){

memset(c,0,sizeof(c));

c[0]=1;//

scanf("%s",b);int num=0;

int len=strlen(b);int shu=0;

for(int i=0;i<len;i++){

a[i]=int(b[i]-'0');

}

 

while(1){

shu=0;num=0;bool flag=1;

for(int i=0;i<len-1;i++){

if(a[i]!=0){

flag=0;

break;

}

}

if(flag&&a[len-1]<2) {

// cout<<"flag"<<a[len-1]<<endl;

break;

}

for(int i=0;i<len;i++){

 int tem=(a[i]+shu*10)%2;

 

a[i]=(a[i]+shu*10)/2;

//if(!a[i]) continue;

shu=tem;

//if(!a[i]) continue;

// cout<<a[i]<<"res"<<i<<endl;

}

//cout<<num<<"run"<<endl;

// c[0]=c[0]*2;

num=0;

for(int j=0;j<len;j++){

if((num+c[j]*2)>=10){

// cout<<c[j]<<"c[j]"<<j<<endl;

int tem=(num+c[j]*2)/10; //cout<<tem<<"tem"<<endl;

c[j]=(num+c[j]*2)%10;

num=tem;

// cout<<c[j]<<"for"<<endl;

// if(c[j+1])

}

else {

c[j]=c[j]*2+num;

// cout<<c[j]<<endl;

num=0;

}

 

 

}

// cout<<"fuck"<<endl;

 

 

}

int k;

for( k=len-1;k>=0;k--){

if(c[k]){

break;

}

}

for(int j=k;j>=0;j--){

cout<<c[j];

}

cout<<endl;

}

return 0;

}

用字符串模擬非常不熟練,要多練練

最好還是要學會用java,因爲字符串太麻煩了,太耗時間了

 

import java.math.BigInteger;

 

import java.util.Scanner;

 

public class Main {

 

public static void main(String[] args) {

 

  Scanner scan=new Scanner(System.in);

 

  int t;

 

  t=scan.nextInt();

 

  for(int i=0;i<t;i++)

 

  {

 

 BigInteger n=scan.nextBigInteger();

 

 

 

     BigInteger a=new BigInteger("1");

 

     BigInteger b=new BigInteger("2");

 

     BigInteger c=a.multiply(b);

 

     if(b.compareTo(n)==0){

 

 System.out.println("2");

 

continue;

 

     }

 

     while(c.compareTo(n)<=0)

 

     {

 

      c=a.multiply(b);

 

      a=c;

 

     }

 

     if(c.compareTo(n)==0)

 

        System.out.println(c);

 

     

 

     else

 

      c=c.divide(b);

 

     System.out.println(c);

 

  }

 

}

}

不要太亂,縮小範圍用常人做的方法就可以了

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章